您的位置:首页 > 编程语言 > Python开发

leetcode Roman to Integer python

2015-11-18 22:49 676 查看
class Solution(object):
def romanToInt(self, s):
"""
:type s: str
:rtype: int
"""
numerals = { "M": 1000, "D": 500, "C": 100, "L": 50, "X": 10, "V": 5, "I": 1 }

sums=0
s=s[::-1]
last=None

for x in s:
if last and numerals[x] < last:
sums-=2*numerals[x]
sums+=numerals[x]
last=numerals[x]
return sums


@link http://www.cnblogs.com/zuoyuan/p/3779688.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: