-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode12.py
More file actions
32 lines (27 loc) · 677 Bytes
/
code12.py
File metadata and controls
32 lines (27 loc) · 677 Bytes
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
"2"
class Solution:
def intToRoman(self, num: int) -> str:
lroma = ['I', 'V', 'X', 'L', 'C', 'D', 'M']
swich = {
'0': [],
'1': [0],
'2': [0, 0],
'3': [0, 0, 0],
'4': [0, 1],
'5': [1],
'6': [1, 0],
'7': [1, 0, 0],
'8': [1, 0, 0, 0],
'9': [0, 2]
}
def tiroma(n, m):
re = ''
for mi in swich[m]:
re += lroma[n * 2 + mi]
return re
res = ''
n = 0
for i in str(num)[::-1]:
res = tiroma(n, i) + res
n += 1
return res