您的位置:首页 > 编程语言 > Python开发

leetcode Integer to Roman python

2015-11-18 22:35 645 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: