Given an integer, convert it to a roman numeral.
Input is guaranteed to be within the range from 1 to 3999.
1 class Solution(object): 2 def intToRoman(self, num): 3 """ 4 :type num: int 5 :rtype: str 6 """ 7 if num > 3999: 8 return "" 9 10 table = [["M", "MM", "MMM"], 11 ["C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"], 12 ["X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"], 13 ["I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"] 14 ] 15 16 digit = [] 17 for i in range(4): 18 digit.append((num / pow(10, 3 - i)) % 10) 19 20 ret = "" 21 for i, d in enumerate(digit): 22 if d != 0: 23 ret += table[i][d - 1] 24 25 return ret