Skip to content

Commit 1ce53b3

Browse files
authored
Create 12-Integer-To-Roman.py
1 parent ee8458b commit 1ce53b3

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

12-Integer-To-Roman.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution:
2+
def intToRoman(self, num: int) -> str:
3+
symList = [["I", 1], ["IV" , 4], ["V" , 5], ["IX" , 9],
4+
["X" , 10], ["XL" , 40], ["L" , 50], ["XC" , 90],
5+
["C" , 100], ["CD", 400], ["D", 500], ["CM", 900],
6+
["M" , 1000]]
7+
res = ""
8+
for sym, val in reversed(symList):
9+
if num // val:
10+
count = num // val
11+
res += (sym * count)
12+
num = num % val
13+
return res

0 commit comments

Comments
 (0)