diff --git a/LeetCode/Problems/Python/Integer to Roman/Integer to Roman.py b/LeetCode/Problems/Python/Integer to Roman/Integer to Roman.py new file mode 100644 index 00000000..e36b8d2c --- /dev/null +++ b/LeetCode/Problems/Python/Integer to Roman/Integer to Roman.py @@ -0,0 +1,9 @@ +class Solution: + def intToRoman(self, num: int) -> str: + d = {1000: 'M', 900: 'CM', 500: 'D', 400: 'CD', 100: 'C', 90: 'XC', 50: 'L', 40: 'XL', 10: 'X', 9: 'IX', 5: 'V', 4: 'IV', 1: 'I'} + res = '' + for k in d: + while num >= k: + res += d[k] + num -= k + return res