13. Roman to Integer
2016-02-20 22:12
666 查看
Given a roman numeral, convert it to an integer.
Input is guaranteed to be within the range from 1 to 3999.
相比Interger to Roman,本题明显要简单一些,按照规则直接翻译就好。
AC代码:
Input is guaranteed to be within the range from 1 to 3999.
相比Interger to Roman,本题明显要简单一些,按照规则直接翻译就好。
AC代码:
class Solution(object): def romanToInt(self, s): roman_to_int = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000} i, num = 0, 0 while i < len(s) - 1: if roman_to_int[s[i]] >= roman_to_int[s[i + 1]]: num += roman_to_int[s[i]] else: num -= roman_to_int[s[i]] i += 1 num += roman_to_int[s[i]] return num
相关文章推荐
- KMP 算法
- Docker pull 出现的 Server error: Status 0 while fetching image layer
- ARP协议的工作原理
- BestCoder Round #73 (div.2)(B)并查集
- Java [Leetcode 278]First Bad Version
- 韬晦术
- 构筑测试体系
- jquery easyui添加图标扩展
- OpenJudge百炼习题解答(C++)--题1936:全在其中
- C#里氏转换/is/as
- UVA_11090_GoingInCycle!!
- 关于async和await的一些误区实例详解
- 费用流解决最优匹配 PKU3686
- Markdown 编辑器集锦
- iOS-真机调试
- Java基础理解
- Android更改桌面应用程序launcher的两种方式
- LinkageError
- win 7 取得最高权限
- bzoj1006: [HNOI2008]神奇的国度