[LeetCode] 12. Integer to Roman
Python
class Solution:
def intToRoman(self, num: int) -> str:
number = [1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000]
symbol = ["I", "IV", "V", "IX", "X", "XL", "L", "XC", "C", "CD", "D", "CM", "M"]
answer = ''
count_symbol = len(symbol) - 1
while num:
count = num // number[count_symbol]
num %= number[count_symbol]
while count:
answer += symbol[count_symbol]
count -= 1
count_symbol -= 1
return answer
댓글남기기