LeeCode-Roman to Integer
来源:互联网 发布:天龙八部3源码 编辑:程序博客网 时间:2024/06/03 04:09
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 <1) return 0; map<char,int> m; m['I'] = 1; m['V'] = 5; m['X'] = 10; m['L'] = 50; m['C'] = 100; m['D'] = 500; m['M'] = 1000; int i = length-1; int sum = m[s[i--]]; while(i>=0) if(m[s[i+1]] > m[s[i]]) sum -= m[s[i--]]; else sum += m[s[i--]]; return sum; }};
0 0
- LeeCode-Roman to Integer
- LEECODE-Roman to Integer
- Integer to Roman & Roman to Integer
- Integer to Roman & Roman to Integer
- LeetCode Roman to Integer && Integer to Roman
- 【leetcode】Roman to Integer | Integer to Roman
- Leetcode - "Roman to Integer" & "Integer to Roman"
- LeetCode:Roman to Integer,Integer to Roman
- Integer to Roman and Roman to Integer
- LeetCode Integer to Roman & Roman to Integer
- Roman to Integer/Integer to Roman
- leetcode - roman to integer & integer to roman
- "Roman to Integer" and "Integer to Roman"
- Roman to Integer &&Integer to Roman
- Roman to Integer and Integer to Roman
- Roman to Integer/Integer to Roman
- LeeCode-String to Integer (atoi)
- LeeCode String to Integer (atoi)
- em和strong span
- Leetcode 10. Regular Expression Matching
- LeeCode-Remove Duplicates from Sorted List
- 对自定义UITableViewCell的理解
- Server Tomcat v8.0 Server at localhost failed to start.java.util.concurrent.ExecutionException: org.
- LeeCode-Roman to Integer
- web项目实战(一)— —开发中问题收集
- Android学习之路
- LeeCode-Swap Nodes in Pairs
- HDU 1023 Train ProblemII
- scrollTo与scrollBy
- android自定义View实现图片上传进度显示(仿手机QQ上传效果)
- solr入门之solr安全控制的研究和实践(一)
- c++第四次作业