题目:12. Integer to Roman
链接:https://leetcode.com/problems/integer-to-roman/description/
将给定的阿拉伯数字转成罗马数字。
class Solution(object):
romanDict = [("I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", ""),
("X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC", ""),
("C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM", ""),
("M", "MM", "MMM", "", "", "", "", "", "")]
def intToRoman(self, num):
"""
:type num: int
:rtype: str
"""
if not str(num):
return ""
return self.romanDict[len(str(num))-1][int(str(num)[0])-1]+self.intToRoman(str(num)[1:len(str(num))])