当前位置:网站首页>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
};
边栏推荐
- How to configure PostgreSQL 12.9 to allow remote connections
- 國產全中文-自動化測試軟件Apifox
- geotrust ov多域名ssl證書一年兩千一百元包含幾個域名?
- 数学知识(欧拉函数)
- Basic differences between Oracle and MySQL (entry level)
- 06 装饰(Decorator)模式
- Vmware安装win10报错:operating system not found
- Virtual machine installation deepin system
- Cache consistency solution - how to ensure the consistency between the cache and the data in the database when changing data
- Application of intelligent robot in agricultural ecology
猜你喜欢

Federal learning: dividing non IID samples according to Dirichlet distribution

Embedded-c language-8-character pointer array / large program implementation

LM09丨费雪逆变换反转网格策略

Cultivate primary and secondary school students' love for educational robots

UNET deployment based on deepstream

Express logistics quick query method, set the unsigned doc No. to refresh and query automatically

Simple and practical accounting software, so that accounts can be checked
![[high speed bus] Introduction to jesd204b](/img/78/1a0a3672e63058da6d98da95aa3cf2.jpg)
[high speed bus] Introduction to jesd204b

Lm09 Fisher inverse transform inversion mesh strategy

Research on the security of ognl and El expressions and memory horse
随机推荐
[bus interface] Axi interface
Introduction to Luogu 3 [circular structure] problem list solution
CubeMx DMA笔记
Summary of main account information of zhengdaliu 4
Its appearance makes competitors tremble. Interpretation of Sony vision-s 02 products
C# 图片显示占用问题
DMA Porter
Solution of DM database unable to open graphical interface
[Yu Yue education] autumn 2021 reference materials of Tongji University
Keil compilation code of CY7C68013A
Vmware安装win10报错:operating system not found
June book news | 9 new books are listed, with a strong lineup and eyes closed!
fastText文本分类
Video cover image setting, put cover images into multiple videos in the simplest way
Lay the foundation for children's programming to become a basic discipline
Win10 disk management compressed volume cannot be started
go实现leetcode旋转数组
Fasttext text text classification
06 装饰(Decorator)模式
Analyzing the hands-on building tutorial in children's programming