Given a roman numeral, convert it to an integer.

Input is guaranteed to be within the range from 1 to 3999.

 class Solution {
public:
int romanToInt(string s) {
int length = s.length();
if(length <) return ;
map<char,int> m;
m['I'] = ;
m['V'] = ;
m['X'] = ;
m['L'] = ;
m['C'] = ;
m['D'] = ;
m['M'] = ;
int i = length-;
int sum = m[s[i--]];
while(i>=)
if(m[s[i+]] > m[s[i]])
sum -= m[s[i--]];
else
sum += m[s[i--]];
return sum;
}
};

LeeCode-Roman to Integer的更多相关文章

  1. 【LeetCode】Roman to Integer & Integer to Roman

    Roman to Integer Given a roman numeral, convert it to an integer. Input is guaranteed to be within t ...

  2. 【leetcode】Integer to Roman & Roman to Integer(easy)

    Roman to Integer Given a roman numeral, convert it to an integer. Input is guaranteed to be within t ...

  3. [LintCode] Roman to Integer 罗马数字转化成整数

    Given a roman numeral, convert it to an integer. The answer is guaranteed to be within the range fro ...

  4. 5.Integer to Roman && Roman to Integer

    Roman chart: http://literacy.kent.edu/Minigrants/Cinci/romanchart.htm Integer to Roman Given an inte ...

  5. LeetCode:Roman to Integer,Integer to Roman

    首先简单介绍一下罗马数字,一下摘自维基百科 罗马数字共有7个,即I(1).V(5).X(10).L(50).C(100).D(500)和M(1000).按照下述的规则可以表示任意正整数.需要注意的是罗 ...

  6. 58. 分析、测试与总结:罗马数字和阿拉伯数字的转换[roman to integer and integer to roman in c++]

    [本文链接] http://www.cnblogs.com/hellogiser/p/roman-to-integer-and-integer-to-roman.html [题目] 给出一个罗马数字, ...

  7. No.013 Roman to Integer

    13. Roman to Integer Total Accepted: 95998 Total Submissions: 234087 Difficulty: Easy Given a roman ...

  8. 【LeetCode】12 & 13 - Integer to Roman & Roman to Integer

    12 - Integer to Roman Given an integer, convert it to a roman numeral. Input is guaranteed to be wit ...

  9. 3月3日(5) Roman to Integer

    原题 Roman to Integer 题意很简单,把Roman字母翻译成int. 实现方式也不难,针对每个字符转成int,从右往左,依次判断,如果当前值比上一个值大则相加,小则相减. 什么,你问我怎 ...

  10. Roman to Integer && Integer to Roman 解答

    Roman Numeral Chart V:5 X:10 L:50 C:100 D:500 M:1000 规则: 1. 重复次数表示该数的倍数2. 右加左减:较大的罗马数字右边记上较小的罗马数字,表示 ...

随机推荐

  1. python高级编程之超类02:super的缺陷

    # -*- coding: utf-8 -*- # python:2.x __author__ = 'Administrator' #当使用多重继承层次结构时,再使用super的时候是非常危险的,主要 ...

  2. xcode6 建立 empty application

    .新建一个single view application .打开 Info.plist,删除里面的 Launch screen interface file....以及 Main storyboard ...

  3. 检测iOS系统的定位服务

    [CLLocationManager locationServicesEnabled]检测的是整个iOS系统的位置服务开关

  4. C库函数笔记

    一.string.h 1.memcpy 函数原型:void *memcpy(void *dest, const void *src, size_t n); 功能:从源src所指的内存地址的起始位置开始 ...

  5. Eclipse代理设置

    这段时间公司实行代理上网,不仅通过浏览器上网须要不停的输入username和password,在本地调试程序时候Eclipse居然也弹出框让输入username和password. 如图: 解决的方法 ...

  6. Error creating bean with name &#39;memcachedClient&#39;...java.lang.OutOfMemoryError

    1,Tomcat启动报错例如以下: Caused by: org.springframework.beans.factory.BeanCreationException: Error creating ...

  7. flashback database操作步骤

    默认情况数据库的flashback database是关闭的. 启用Flashback Database 步骤:1.配置Flash Recovery Area 检查是否启动了flash recover ...

  8. border-radius讲解1

    如今CSS3中的border-radius出现后,让我们没有那么多的烦恼了,首先制作圆角图片的时间是省了,而且其还有多个优点:其一减少网站的维护的工作量,少了对图片的更新制作,代码的替换等等;其二.提 ...

  9. ArcGIS10.3.1于2015年6月发布

    http://www.esrichina.com.cn/sectorapplication/ArcGIS%2010.3/index.html

  10. textView富文本点击事件

    NSDictionary * attDic = [NSDictionary dictionaryWithObjectsAndKeys:RGBCOLOR(31, 132, 204),NSForegrou ...