classSolution(object): defintToRoman(self, num): """ :type num: int :rtype: str """ if num isNoneor num == 0: return"" integers = [1000, 100, 10, 1] romans = [['M'], ['C', 'D'], ['X', 'L'], ['I', 'V']] roman = [] for i, j in enumerate(integers): if num < j: continue digit = num // j if digit < 4: for k in range(digit): roman.append(romans[i][0]) elif digit == 4: roman.append(romans[i][0]) roman.append(romans[i][1]) elif digit < 9: roman.append(romans[i][1]) for k in range(digit - 5): roman.append(romans[i][0]) else: roman.append(romans[i][0]) roman.append(romans[i - 1][0]) num %= j return''.join(roman)