013 Roman to Integer 罗马数字转整数
给定一个罗马数字,将其转换成整数。
返回的结果要求在 1 到 3999 的范围内。
详见:https://leetcode.com/problems/roman-to-integer/description/
- class Solution {
- public:
- int romanToInt(string s) {
- int res=0;
- map<char, int> m{{'I', 1}, {'V', 5}, {'X', 10}, {'L', 50}, {'C', 100}, {'D', 500}, {'M', 1000}};
- for(int i=0;i<s.size();++i)
- {
- if(i==s.size()-1||m[s[i+1]]<=m[s[i]])
- res+=m[s[i]];
- else
- res-=m[s[i]];
- }
- return res;
- }
- };
参考:http://www.cnblogs.com/grandyang/p/4120857.html
013 Roman to Integer 罗马数字转整数的更多相关文章
- LeetCode 13 Roman to Integer(罗马数字转为整数)
题目链接 https://leetcode.com/problems/roman-to-integer/?tab=Description int toNumber(char ch) { switc ...
- 【LeetCode】13. Roman to Integer 罗马数字转整数
题目: Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from ...
- [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】Roman to Integer(罗马数字转整数)
这道题是LeetCode里的第13道题. 题目说明: 罗马数字包含以下七种字符: I, V, X, L,C,D 和 M. 字符 数值 I 1 V 5 X 10 L 50 C 100 D 500 M 1 ...
- [LintCode] Roman to Integer 罗马数字转化成整数
Given a roman numeral, convert it to an integer. The answer is guaranteed to be within the range fro ...
- No.013 Roman to Integer
13. Roman to Integer Total Accepted: 95998 Total Submissions: 234087 Difficulty: Easy Given a roman ...
- LeetCode--No.013 Roman to Integer
13. Roman to Integer Total Accepted: 95998 Total Submissions: 234087 Difficulty: Easy Given a roman ...
- [Leetcode] Roman to integer 罗马数字转成整数
Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 t ...
- [LeetCode] Roman to Integer 罗马数字转化成整数
Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 t ...
随机推荐
- BZOJ2548:[CTSC2002]灭鼠行动
我对模拟的理解:https://www.cnblogs.com/AKMer/p/9064018.html 题目传送门:https://www.lydsy.com/JudgeOnline/problem ...
- CF1092 D & E —— 思路+单调栈,树的直径
题目:https://codeforces.com/contest/1092/problem/D1 https://codeforces.com/contest/1092/problem/D2 htt ...
- 转:删除redis所有KEY
转自:http://ssuupv.blog.163.com/blog/static/1461567220135610456193/ 批量删除Key Redis 中有删除单个 Key 的指令 DEL,但 ...
- 巧用函数实现js插入css样式
我用的是webstorm,当写css 样式时候,会没有提示,可以按Ctrl+Alt+Space.
- STL string大小写 转换
std::string data = "This is a sample string."; // convert string to upper case std::for_ea ...
- JSP介绍(3)---JSP表单处理
GET方法: GET方法将请求的编码信息添加在网址后面,网址与编码信息通过"?"号分隔.如下所示: http://www.runoob.com/hello?key1=value1& ...
- python 链表
在C/C++中,通常采用“指针+结构体”来实现链表:而在Python中,则可以采用“引用+类”来实现链表. 节点类: class Node: def __init__(self, data): sel ...
- JVM类加载(3)—初始化
3.初始化 在准备阶段,变量已经赋过一次系统要求的初始值,而在初始化阶段,则根据程序员通过程序制定的主观计划去初始化类变量(静态变量)和其他资源,或者从另外一个角度表达:初始化过程是执行类构造器< ...
- Java enum(枚举)使用详解之二
enum 对象的常用方法介绍 int compareTo(E o) 比较此枚举与指定对象的顺序. Class<E> getDeclaringClass() ...
- position应用之相对父元素的定位
分别添加以下style即可: 父元素position:relative; 子元素position:absolute; right:0px; bottom:0px;