首页 > 编程语言 > 详细

leetcode Roman to Integer python

时间:2015-11-19 00:18:06      阅读:267      评论:0      收藏:0      [点我收藏+]
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

leetcode Roman to Integer python

原文:http://www.cnblogs.com/allenhaozi/p/4976166.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!