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

posted @ 2015-11-18 22:49  hao.ma  阅读(125)  评论(0编辑  收藏  举报