Skip to content

Commit f8e649d

Browse files
committed
committed from zkp
1 parent 39a76e0 commit f8e649d

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

LeetCode/intToRoman.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution:
2+
def intToRoman(self, num):
3+
"""
4+
:type num: int
5+
:rtype: str
6+
"""
7+
L = {1 : 'I',4 : 'IV',5 : 'V',9 : 'IX',10 : 'X',40 : 'XL',50 : 'L',90 : 'XC',100 : 'C',400 : 'CD',500 :'D',900 :'CM',1000 : 'M'}
8+
k = [1000,900,500,400,100,90,50,40,10,9,5,4,1]
9+
a = num
10+
s = ''
11+
while a>0:
12+
u = sorted(([a]+k), reverse = True)
13+
# print(u)
14+
n = u[u.index(a)+1]
15+
s += L[n]
16+
a -= n
17+
return s

0 commit comments

Comments
 (0)