leetcode 13 Roman to Integer 罗马数组转整型
描述:
将一个字符串表示的罗马数字转为整数,范围0~3999
解决:
如果后一个比前一个大,则表示减,没什么技巧。
map<char, int> m = {{'I', }, {'V', }, {'X', }, {'L', }, {'C', }, {'M', }, {'D', }};
int romanToInt(string s) {
int ret = ;
int last = ;
for (auto i : s) {
if (m[i] > last) {
ret = ret - last - last + m[i];
last = ;
}
else
ret = ret + m[i];
last = m[i];
}
return ret;
}
leetcode 13 Roman to Integer 罗马数组转整型的更多相关文章
- Leetcode#13. Roman to Integer(罗马数字转整数)
题目描述 罗马数字包含以下七种字符:I, V, X, L,C,D 和 M. 字符 数值 I 1 V 5 X 10 L 50 C 100 D 500 M 1000 例如, 罗马数字 2 写做 II ,即 ...
- Leetcode 13. Roman to Integer(水)
13. Roman to Integer Easy Roman numerals are represented by seven different symbols: I, V, X, L, C, ...
- [LeetCode] 13. Roman to Integer 罗马数字转化成整数
Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. Symbol Value I 1 ...
- LeetCode - 13. Roman to Integer - 思考if-else与switch的比较 - ( C++ ) - 解题报告
1.题目: 原题:Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range ...
- Java [leetcode 13] Roman to Integer
问题描述: Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range fr ...
- LeetCode 13. Roman to Integer(c语言版)
题意: Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. Symbol Value ...
- LeetCode 13 Roman to Integer 解题报告
题目要求 Roman numerals are represented by seven different symbols: I, V, X, L, C, Dand M. Symbol Value ...
- [leetcode]13. Roman to Integer罗马数字转整数
Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. Symbol Value I 1 ...
- LeetCode——13. Roman to Integer
一.题目链接:https://leetcode.com/problems/roman-to-integer/ 二.题目大意: 给定一个罗马数字,返回它的整数形式. 三.题解: 这道题与12题恰好相反, ...
随机推荐
- linux提权辅助工具(二):linux-exploit-suggester-2.pl
来自:https://github.com/jondonas/linux-exploit-suggester-2/blob/master/linux-exploit-suggester-2.pl #! ...
- C#中IEnumerable和IEnumerator区别
IEnumerator:是一个真正的集合访问器,提供在普通集合中遍历的接口,有Current,MoveNext(),Reset(),其中Current返回的是object类型.IEnumerable: ...
- ubuntu16.04x64环境下 tar方式 安装mysql-5.7.21 试水过程记录
前几天读研时候上铺的同学和我说到了一个问题,就是他们单位的redhat服务器给MySQL服务的数据库文件所在的磁盘空间不够了,对于这个问题我也是没有想过的,在受朋友之托下考虑自己做下复现,由于同学所在 ...
- BZOJ3293: [Cqoi2011]分金币(数学)
3293: [Cqoi2011]分金币 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1596 Solved: 969[Submit][Status ...
- 深入__proto__和prototype的区别和联系
前话 有一个一个装逼的同事,写了一段代码 function a(){} a.__proto__.__proto__.__proto__ 然后问我,下面这个玩意a.__proto__.__proto__ ...
- python3文件操作方法
在python3中,我们可以使用open打开一个文件,那么打开文件后,文件有什么操作方法呢?接下来我就记录一下比较常用的方法. 1. close() 关闭打开的文件 2. fileno() 返回文件句 ...
- iframe相关知识
iframe 不带边框的iframe因为能和网页无缝的结合从而不刷新页面的情况下更新页面的部分数据成为可能,可是 iframe的大小却不像层那样可以“伸缩自如”,所以带来了使用上的麻烦.一般通过百分比 ...
- streamsets 丢踢无关数据
对于不需要的数据,streamsets 可以方便的设置丢踢,我们可以通过定义require 字段或者前置条件进行配置 require(必须字段) 必须字段是必须存在一条record 中的,对于不存在的 ...
- Hive之 hive与hadoop的联系
Hive与Hadoop调用图 解析: 1.提交sql 交给驱动2.驱动编译:解析相关的字段表信息3.去metastore查询相关的信息 返回字段表信息4.编译返回信息 发给驱动5.驱动发送一个执行计划 ...
- tomcat 注冊成操作系統服務
nginx注冊成服務1.把srvany.exe和instsrv.exe拷貝到nginx安裝路徑下面.2.執行命令Command代碼instsrv Nginx D:\nginx\srvany.exe3. ...