当前位置:网站首页>js中的Map(含leetcode例题)
js中的Map(含leetcode例题)
2022-07-02 04:58:00 【走出自闭的鸟儿】
Map
JS为我们提供了现成的Map结构,可以理解为一组键值对
leetcode例题
之前在数组一节中也在很多地方使用到了map
JS中的数组(含leetcode例题)<持续更新~>
13. 罗马数字转整数
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
};
边栏推荐
- Gin framework learning code
- About PROFIBUS: communication backbone network of production plant
- 培养中小学生对教育机器人的热爱之心
- I sorted out some basic questions about opencv AI kit.
- Let正版短信测压开源源码
- oracle 存储过程与job任务设置
- Analyze the space occupied by the table according to segments, clusters and pages
- 洛谷入门3【循环结构】题单题解
- 正大美欧4的主账户关注什么数据?
- Acelems Expressway microgrid energy efficiency management platform and intelligent lighting solution intelligent lighting tunnel
猜你喜欢
MySQL table insert Chinese change? Solution to the problem of No
How to modify data file path in DM database
LM09丨费雪逆变换反转网格策略
2022 Alibaba global mathematics competition, question 4, huhushengwei (blind box problem, truck problem) solution ideas
Orthogonal test method and function diagram method for test case design
LeetCode-归并排序链表
Video multiple effects production, fade in effect and border background are added at the same time
Research on the security of ognl and El expressions and memory horse
[high speed bus] Introduction to jesd204b
DC-1靶场搭建及渗透实战详细过程(DC靶场系列)
随机推荐
How to configure PostgreSQL 12.9 to allow remote connections
数学问题(数论)试除法做质数的判断、分解质因数,筛质数
Markdown edit syntax
win10 磁盘管理 压缩卷 无法启动问题
Let正版短信测压开源源码
GeoTrust ov multi domain SSL certificate is 2100 yuan a year. How many domain names does it contain?
Pyflink writes MySQL examples with JDBC
Research on the security of ognl and El expressions and memory horse
Use of typescript classes
2022-003arts: recursive routine of binary tree
CubeMx DMA笔记
js面试收藏试题1
[bus interface] Axi interface
Record the bug of unity 2020.3.31f1 once
[Yu Yue education] autumn 2021 reference materials of Tongji University
Steam教育的实际问题解决能力
Mouse events in JS
Knowledge arrangement about steam Education
VMware installation win10 reports an error: operating system not found
About PROFIBUS: communication backbone network of production plant