-
Notifications
You must be signed in to change notification settings - Fork 0
/
12. Integer to Roman.py
44 lines (44 loc) · 1.04 KB
/
12. Integer to Roman.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
class Solution:
def intToRoman(self, num: int) -> str:
s=""
while num>0:
if num>=1000:
s+="M"
num-=1000
elif num>=900:
s+="CM"
num-=900
elif num>=500:
s+="D"
num-=500
elif num>=400:
s+="CD"
num-=400
elif num>=100:
s+="C"
num-=100
elif num>=90:
s+="XC"
num-=90
elif num>=50:
s+="L"
num-=50
elif num>=40:
s+="XL"
num-=40
elif num>=10:
s+="X"
num-=10
elif num>=9:
s+="IX"
num-=9
elif num>=5:
s+="V"
num-=5
elif num>=4:
s+="IV"
num-=4
else:
s+=("I"*num)
num-=num
return s