leetcode Roman to Integer python
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