Given a roman numeral, convert it to an integer.

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

roman numerals: https://en.wikipedia.org/wiki/Roman_numerals

Solution 1:

class Solution
{
public:
inline int romanInt(const char c)
{
switch(c)
{
case 'I': return ;
case 'V': return ;
case 'X': return ;
case 'L': return ;
case 'C': return ;
case 'D': return ;
case 'M': return ;
default: return ;
}
} int romanToInt(string s)
{
int result = ;
for(size_t i = ; i < s.size(); ++i)
{
if(i > && romanInt(s[i]) > romanInt(s[i - ]))
{
result += (romanInt(s[i]) - * romanInt(s[i - ]));
}
else
result += romanInt(s[i]);
}
return result;
}
};

Solution 2:

Roman to Integer -- LeetCode 13的更多相关文章

  1. Roman to Integer [LeetCode]

    Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 t ...

  2. Roman To Integer leetcode java

    问题描述: Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range fr ...

  3. LeetCode 13. 罗马数字转整数(Roman to Integer)

    13. 罗马数字转整数 13. Roman to Integer 题目描述 罗马数字包含以下七种字符: I,V,X,L,C,D 和 M. 字符        数值  I           1  V  ...

  4. 【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 ...

  5. 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 ,即 ...

  6. C# 写 LeetCode easy #13 Roman to Integer

    13.Roman to Integer Roman numerals are represented by seven different symbols: I, V, X, L, C, D and  ...

  7. Leetcode 13. Roman to Integer(水)

    13. Roman to Integer Easy Roman numerals are represented by seven different symbols: I, V, X, L, C, ...

  8. leetCode练题——13. Roman to Integer

    1.题目13. Roman to Integer Roman numerals are represented by seven different symbols: I, V, X, L, C, D ...

  9. 13. Roman to Integer【leetcode】

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

随机推荐

  1. Intent意图

    1.显式Intent button1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(Vie ...

  2. 常用webservice接口

    商业和贸易: 1.股票行情数据 WEB 服务(支持香港.深圳.上海基金.债券和股票:支持多股票同时查询) Endpoint: http://webservice.webxml.com.cn/WebSe ...

  3. CSSOM之getboundingclientrect和getclientrects

    TextRectangle 对于文本对象,W3C提供了一个 TextRectangle 对象,这个对象是对文本区域的一个解释. 对于 i,span,em等display 是inline的标签,在书写文 ...

  4. js之oop <二> 对象属性

    js中对象属性可以动态添加和删除.删除对象属性用delete关键字. function obj(){ } var oo = new obj(); oo.a = "a"; oo.b ...

  5. 使用新版Android Studio检测内存泄露和性能

    内存泄露,是Android开发者最头疼的事.可能一处小小的内存泄露,都可能是毁于千里之堤的蚁穴.  怎么才能检测内存泄露呢?网上教程非常多,不过很多都是使用Eclipse检测的, 其实1.3版本以后的 ...

  6. easyui-panel 滚动条禁用

    div id="p" class="easyui-panel" title="title" style="padding:10px ...

  7. lr各种问题以及解决办法

    LR 脚本为空的解决方法: 1.去掉ie设置中的第三方支持取消掉 2.在系统属性-高级-性能-数据执行保护中,添加loadrunner安装目录中的vugen.exe文件 遇到flight界面为空的解决 ...

  8. office openxml学习(一)

    以前用过,aspose.dll处理word ,excel,之后发现 npoi,使用了一段时间,总觉得是第三方,不明白底层的实现,直到最近发现了office openxml ,其实这个技术,很久以前就有 ...

  9. PDF 补丁丁 0.4.3.1582 测试版发布:修复上一测试版的问题

    新的测试版修复了上一测试版在各功能的文件列表中无法更改单元格文本等一系列问题. 软件界面也略有调整,使新测试版更容易使用.建议下载了旧测试版的用户马上更新到新的测试版.

  10. linux getch()实现

    #include <termio.h> int getch(void){     struct termios tm, tm_old;     int fd = 0, ch;       ...