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

Leetcode 12. Integer to Roman The Solution of Python

2017-04-16 21:47 561 查看
Given an integer, convert it to a roman numeral.

Input is guaranteed to be within the range from 1 to 3999.

Python:

class Solution(object):
def intToRoman(self, num):
"""
:type num: int
:rtype: str
"""
digit=["","I","II","III","IV","V","VI","VII","VIII","IX"];
ten=["","X","XX","XXX","XL","L","LX","LXX","LXXX","XC"];
hundred=["","C","CC","CCC","CD","D","DC","DCC","DCCC","CM"];
thousand=["","M","MM","MMM"];
return thousand[num/1000]+hundred[(num%1000)/100]+ten[(num%100)/10]+digit[num%10];


没啥意思,做了一个罗马字母的字典,然后对应求得结果。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  leetcode python