当前位置:网站首页>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
};
边栏推荐
- Pytest learning ----- pytest assertion of interface automation testing
- Line by line explanation of yolox source code of anchor free series network (7) -- obj in head_ loss、Cls_ Loss and reg_ Calculation and reverse transmission of loss I
- Future trend of automated testing ----- self healing technology
- 06 装饰(Decorator)模式
- Ruby replaces gem Alibaba image
- UNET deployment based on deepstream
- Online incremental migration of DM database
- What are the rules and trading hours of agricultural futures contracts? How much is the handling fee deposit?
- JS interview collection test question 1
- Hcip day 17
猜你喜欢
ansible安装与使用
Detailed process of DC-1 range construction and penetration practice (DC range Series)
Mysql表insert中文变?号的问题解决办法
About PROFIBUS: communication backbone network of production plant
Preparation for writing SAP ui5 applications using typescript
How to recover deleted data in disk
Research on the security of ognl and El expressions and memory horse
Leetcode merge sort linked list
Embedded-c language-9-makefile/ structure / Consortium
2022-003arts: recursive routine of binary tree
随机推荐
06 decorator mode
培养中小学生对教育机器人的热爱之心
Basic differences between Oracle and MySQL (entry level)
Mysql表insert中文变?号的问题解决办法
Getting started with pytest ----- confitest Application of PY
UNET deployment based on deepstream
Comp 250 parsing
Lm09 Fisher inverse transform inversion mesh strategy
Simple and practical accounting software, so that accounts can be checked
DJB Hash
idea自動導包和自動删包設置
Video multiple effects production, fade in effect and border background are added at the same time
案例分享|智慧化的西部机场
leetcode存在重复元素go实现
Social media search engine optimization and its importance
Keil compilation code of CY7C68013A
Embedded-c language-8-character pointer array / large program implementation
Oracle stored procedure and job task setting
记录一次Unity 2020.3.31f1的bug
Beginner crawler - biqu Pavilion crawler