mirror of
https://github.com/devenperez/leetcode.git
synced 2026-06-13 03:27:07 +00:00
Time: 42 ms (85.09%), Space: 13.5 MB (40.20%) - LeetHub
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
class Solution(object):
|
||||
def intToRoman(self, num):
|
||||
"""
|
||||
:type num: int
|
||||
:rtype: str
|
||||
"""
|
||||
# Conversions in decending order
|
||||
numConv = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1]
|
||||
romConv = ["M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"]
|
||||
|
||||
# Conversions
|
||||
roman = ""
|
||||
for i in range(len(numConv)):
|
||||
while num >= numConv[i]:
|
||||
roman += romConv[i]
|
||||
num -= numConv[i]
|
||||
|
||||
return roman
|
||||
Reference in New Issue
Block a user