首页 > 编程语言 > 详细

leetcode Integer to Roman python

时间:2015-11-19 00:24:36      阅读:293      评论:0      收藏:0      [点我收藏+]
class Solution(object):
    def intToRoman(self, num):
        """
        :type num: int
        :rtype: str
        """
        if num > 3999 or num < 1:
            return ""
        values = [1000,900,500,400,100,90,50,40,10,9,5,4,1]
        numerals = ["M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"]
        lists=‘‘
        for i in range(0,len(values)):
            while num >= values[i]:
                num -= values[i]
                lists += numerals[i]
        return lists
        

@link http://www.cnblogs.com/zuoyuan/p/3779581.html

leetcode Integer to Roman python

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

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