Roman to Integer -- LeetCode 13
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的更多相关文章
- Roman to Integer [LeetCode]
Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 t ...
- Roman To Integer leetcode java
问题描述: Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range fr ...
- LeetCode 13. 罗马数字转整数(Roman to Integer)
13. 罗马数字转整数 13. Roman to Integer 题目描述 罗马数字包含以下七种字符: I,V,X,L,C,D 和 M. 字符 数值 I 1 V ...
- 【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 ...
- 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 ,即 ...
- 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 ...
- 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
1.题目13. Roman to Integer Roman numerals are represented by seven different symbols: I, V, X, L, C, D ...
- 13. Roman to Integer【leetcode】
Roman to Integer Given a roman numeral, convert it to an integer. Input is guaranteed to be within t ...
随机推荐
- 制作图片边框:《CSS3 Border-image》
一个边框图片border-image
- (转)使用myeclipse生成实体类和hibernate映射文件
转至:http://blog.sina.com.cn/s/blog_9658bdb40100uiod.html 1.下载并安装myeclipse,如果已经安装,则忽略该步骤; 2.打开myeclips ...
- EXCEL数据透视相关知识
要边看边总结要点:1.部门管理,标准化作业流程,控制生产经营过程,预知风险2.这一项内容,用一个工作薄三个SHEET表来完成.分类汇总表(可变,N个),源数据表(标准.规范.通用.简洁.正确),1.符 ...
- VS2010/2012配置优化记录笔记
VS2010/2012配置优化记录笔记 在某些情况下VS2010/2012运行真的实在是太卡了,有什么办法可以提高速度吗?下面介绍几个优化策略,感兴趣的朋友可以参考下,希望可以帮助到你 有的时候V ...
- javascript实现动态侧边栏
总的来说就是利用 鼠标悬停onmouseover 和 鼠标移除onmouseout 这两个时间来完成的. 首先是HTML 结构 <body> <div id="div ...
- django admin下拉列表不显示值,显示为object的处理
问题:模板中创建form表单中的下拉列表, 前台打开页面显示object,而不是值,如图: 尝试了多种办法无果,最后解决了,处理办法是修改models.py,原来的model: class Techn ...
- Hello World for U
题目描述: Given any ) characters, you are asked to form the characters into the shape of U. For example, ...
- redis 数据导出
一.导出所有的keys echo "keys 201*" |./redis-cli -h localhost -p 6379 -a password >> 1.txt ...
- 用Redis Desktop Manager连接Redis
Redis Desktop Manager是Redis图形化管理工具,方便管理人员更方便直观地管理Redis数据. 然而在使用Redis Desktop Manager之前,有几个要素需要注意: 一. ...
- Java通过jedis操作redis缓存
package com.wodexiangce.util; import java.util.Set; import redis.clients.jedis.Jedis; /** * redis工具类 ...