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

相关文章:

  • 2021-05-22
  • 2022-02-12
  • 2021-11-24
  • 2021-12-28
  • 2021-11-22
  • 2022-03-01
  • 2022-02-19
  • 2021-12-29
猜你喜欢
  • 2021-12-31
  • 2021-07-24
  • 2021-10-04
  • 2021-10-29
  • 2022-02-15
  • 2021-07-08
  • 2022-12-23
相关资源
相似解决方案