forked from yubinbai/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
20 lines (17 loc) · 640 Bytes
/
main.py
File metadata and controls
20 lines (17 loc) · 640 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class Solution:
# @return a string
def intToRoman(self, num):
romanNumbers = ["M", "CM", "D", "CD", "C",
"XC", "L", "XL", "X", "IX", "V", "IV", "I"]
val = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1]
converted = []
for i in range(len(romanNumbers)):
d, num = divmod(num, val[i])
converted.append(romanNumbers[i] * d)
return ''.join(converted)
if __name__ == '__main__':
s = Solution()
# for i in range(1, 200): print(s.intToRoman(i))
print(s.intToRoman(400))
print(s.intToRoman(1980))
print(s.intToRoman(3999))