leetcode——13——Roman to Integer
来源:互联网 发布:软件测试资质 编辑:程序博客网 时间:2024/04/30 07:07
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) { unordered_map<char, int> map = {{'I', 1}, {'V', 5}, {'X', 10}, {'L', 50}, {'C', 100}, {'D', 500}, {'M', 1000}}; int sum=0; for (int i = 0;i<s.size();i++) { sum+=map[s[i]]; if(i>0 &&map[s[i-1]] < map[s[i]]) sum=sum-2*map[s[i-1]]; } return sum ; }};
0 0
- leetcode— Integer to Roman
- #13 LeetCode——Roman to Integer
- LeetCode——Integer to Roman
- LeetCode——Integer to Roman
- LeetCode——Roman to Integer
- leetcode 012 —— Integer to Roman
- leetcode 013 —— Roman to Integer
- LeetCode题解——Roman to Integer
- LeetCode题解——Integer to Roman
- #12 LeetCode——Integer to Roman
- 【LeetCode】LeetCode——第13题:Roman to Integer
- leetcode——13——Roman to Integer
- leetcode第13题——*Roman to Integer
- 【leetcode】String——Roman to Integer(13)
- 刷LeetCode(13)——Roman to Integer
- LeetCode 13 Roman to Integer (easy)——python
- Leetcode习题记录——Integer to Roman 和 Roman to Integer
- 【LeetCode】LeetCode——第12题:Integer to Roman
- aaa
- Android-按钮效果
- pthread
- Python3:在0-1之间生成10个随机数
- Android沉浸式状态栏兼容4.4手机的实现
- leetcode——13——Roman to Integer
- Struts2 提交表单无法接收input disabled的值
- SEO策略之让别人主动链接你——链接诱饵
- 设计模式---代理模式
- zynq之petalinux安装和编译
- 关于Lucene以及索引和搜索的流程
- UIBezierPath贝塞尔弧线常用方法记 (2012-09-19 21:34:56)
- lintcode:Copy Books
- POJ 1017