Given a roman numeral, convert it to an integer.
Input is guaranteed to be within the range from 1 to 3999.
class Solution(object): def romanToInt(self, s): """ :type s: str :rtype: int """ numList = {'I':1, 'V':5, 'X':10, 'L':50, 'C':100, 'D':500, 'M':1000} L = len(s) re = numList[s[-1]] for i in range(L-2, -1, -1): if numList[s[i]] < numList[s[i+1]]: re -= numList[s[i]] else: re += numList[s[i]] return re
相关推荐
leetcode上Roman to Integer的完整C++代码,已被accepted
LeetCode Roman to Integer解决方案
13. 罗马数字转整数 Roman to Integer用哈希存储映射字符--->对映的值对字符串的字符挨个判断,考虑下一个字符如果下一个字符大于当前字符,su
c c语言_leetcode 0013_roman_to_integer.zip
java入门 java_leetcode题解之013_Roman_to_Integer
js js_leetcode题解之13-roman-to-integer.js
c语言入门 C语言_leetcode题解之13-roman-to-integer.c
java入门 java_leetcode题解之012_Integer_to_Roman
js js_leetcode题解之12-integer-to-roman.js
c语言入门 C语言_leetcode题解之12-integer-to-roman.c
13. Roman to Integer 15. 3Sum 16. 3Sum Closest 17. Letter Combinations of a Phone Number 18. 4Sum 19. Remove Nth Node From End of List 20. Valid Parentheses 21. Merge Two Sorted Lists 22. Generate ...
Integer 8.String To Integer 9.Palindrome Number 10.String To Integer 11.Container With Most Water 12.Integer To Roman 13.Roman To Integer 289 347 380 442 457 Circular Array Loop 535 Encode and Decode ...
Integer 008 String to Integer (atoi) 009 Palindrome Number 010 Regular Expression Matching 011 Container With Most Water 012 Integer to Roman 013 Roman to Integer 014 Longest Common Prefix 015 3Sum ...
Flamg The flames of youth are raging. 解题口诀 动规递归是神器, 全无用处想哈希。... Integer to Roman][23]][24] [![13. Roman to Integer][25]][26] [![14. Longest Common Prefix][27]][28] [!
7. **项目结构**:"Conversion.roman-to-decimalANDdecimal-to-roman-master"这个压缩包名称暗示了项目的核心部分可能有一个名为"roman-to-decimalANDdecimal-to-roman"的主代码文件或目录,可能包含源代码、测试...
Integer 简单 字串 String to Integer (atoi) 中等 字串 麻烦 Palindrome Number 简单 字串 Container With Most Water 中等 动态规划 重要 Integer to Roman 中等 重要 Roman to Integer 简单 重要 Longest Common ...
Integer 008. String to Integer 009. Palindrome Number 010. Regular Expression Matching 011. Container With Most Water 012. Integer to Roman 013. Roman to Integer 014. Longest Common Prefix 019. R
Integer 简单 8 String to Integer (atoi) 中等 9 Palindrome Number 简单 11 Container With Most Water 中等 12 Integer to Roman 中等 13 Roman to Integer 简单 14 Longest Common Prefix 简单 15 3Sum 中等 16 ...
Integer 8.String to Integer (atoi) 9.Palindrome Number 10.Regular Expression Matching 11.Container With Most Water 12.Integer to Roman 13.Roman to Integer 14.Longest Common Prefix (Trie树待完成) 15.3...