13. Roman to Integer leetcode Python 2016 new Season
来源:互联网 发布:mac 拷贝隐藏文件 编辑:程序博客网 时间:2024/05/22 06:22
Given a roman numeral, convert it to an integer.
Input is guaranteed to be within the range from 1 to 3999.
O(n) time go through the whole string. O(1) space.
class Solution(object): def romanToInt(self, s): """ :type s: str :rtype: int """ ROMAN_HASH = { 'M' : 1000, 'D' : 500, 'C' : 100, 'L' : 50, 'X' : 10, 'V' : 5, 'I' : 1 } total_value = 0 previous_value = 0 for char in s: current_value = ROMAN_HASH[char] if previous_value < current_value: total_value += current_value - 2 * previous_value else: total_value += current_value previous_value = current_value return total_value
0 0
- 13. Roman to Integer leetcode Python 2016 new Season
- 12. Integer to Roman python leetcode 2016 new Season
- 13. Roman to Integer Leetcode Python
- [leetcode:python]13.Roman to Integer
- 【Leetcode】【python】Integer to Roman
- 【Leetcode】【python】Roman to Integer
- Leetcode-Roman to Integer-Python
- LeetCode 13. Roman to Integer
- [LeetCode]13.Roman to Integer
- LeetCode --- 13. Roman to Integer
- [Leetcode] 13. Roman to Integer
- [leetcode] 13.Roman to Integer
- leetcode 13. Roman to Integer
- leetcode 13. Roman to Integer
- LeetCode 13. Roman to Integer
- [LeetCode]13. Roman to Integer
- Leetcode 13. Roman to Integer
- leetcode 13. Roman to Integer
- zoj 3777 Problem Arrangement 【状压dp】
- connect()函数阻塞
- 1007. 素数对猜想 (20)
- Android摄像头基础
- HDU1002 A + B Problem II
- 13. Roman to Integer leetcode Python 2016 new Season
- 在rt5350 openwrt系统下spi的rtc ds3234配置
- 从小米想到的商业模式创新
- android中xml tools详解
- struts的过滤器代码
- 欢迎使用CSDN-markdown编辑器
- Qt Creator下载和安装(详细教程)
- linux 下的phpstudy 添加 mysql 为环境变量
- 【Unity开发】UNITY实现断点续传