-
Notifications
You must be signed in to change notification settings - Fork 19
/
answer.py
35 lines (25 loc) · 934 Bytes
/
answer.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
#!/usr/bin/python
#------------------------------------------------------------------------------
class Solution(object):
def intToRoman(self, num):
"""
:type num: int
:rtype: str
"""
result = ""
# Create lists of possible roman numerals
M = ["", "M", "MM", "MMM"];
C = ["", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"];
X = ["", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"];
I = ["", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"];
# Perform calculations and append to result
result += M[num / 1000]
result += C[(num % 1000) / 100]
result += X[(num % 100) / 10]
result += I[num % 10]
return result
#------------------------------------------------------------------------------
#Testing
def main():
print Solution().intToRoman(3114)
main()