当前位置:网站首页>Map in JS (including leetcode examples)
Map in JS (including leetcode examples)
2022-07-02 05:00:00 【Out of the autistic bird】
Map
JS Provide us with ready-made Map structure , It can be understood as a set of key value pairs
For specific usage, please refer to teacher Ruan Yifeng's article
leetcode Example
It was also used in many places in the section of array map
JS In the array ( contain leetcode Example )< Continuous updating ~>
13. Roman numeral to integer
var romanToInt = function(s) {
let res =0
let map = new Map([
['I',1],
['V',5],
['X',10],
['L',50],
['C',100],
['D',500],
['M',1000],
])
let length = s.length
for(let i=0;i<length;i++){
let value = map.get(s[i])
if(i<length&&value<map.get(s[i+1])){
res = res - map.get(s[i])
}else{
res = res + map.get(s[i])
}
}
return res
};
边栏推荐
- Social media search engine optimization and its importance
- Leetcode- insert and sort the linked list
- CubeMx DMA笔记
- The underlying principle of go map (storage and capacity expansion)
- 面试会问的 Promise.all()
- UNET deployment based on deepstream
- 初学爬虫-笔趣阁爬虫
- Solution of DM database unable to open graphical interface
- Cannot activate CONDA virtual environment in vscode
- Introduction to Luogu 3 [circular structure] problem list solution
猜你喜欢
06 装饰(Decorator)模式
VMware installation win10 reports an error: operating system not found
How to recover deleted data in disk
Its appearance makes competitors tremble. Interpretation of Sony vision-s 02 products
Rhcsa --- work on the third day
Cannot activate CONDA virtual environment in vscode
Simple and practical accounting software, so that accounts can be checked
UNET deployment based on deepstream
Typescript function details
Future trend of automated testing ----- self healing technology
随机推荐
CubeMx DMA笔记
面试会问的 Promise.all()
Embedded-c language-9-makefile/ structure / Consortium
2022-003arts: recursive routine of binary tree
Domestic all Chinese automatic test software apifox
oracle 存储过程与job任务设置
Comp 250 parsing
A new attribute value must be added to the entity entity class in the code, but there is no corresponding column in the database table
6.30年终小结,学生时代结束
Oracle和MySQL的基本区别(入门级)
C# 图片显示占用问题
6.30 year end summary, end of student age
Analyzing the hands-on building tutorial in children's programming
Video multiple effects production, fade in effect and border background are added at the same time
国产全中文-自动化测试软件Apifox
Preparation for writing SAP ui5 applications using typescript
Pytest learning ----- pytest assertion of interface automation testing
C# 基于MQTTNet的服务端与客户端通信案例
Pit encountered in win11 pytorch GPU installation
Typescript function details