-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRoman_to_integer_1.py
50 lines (42 loc) · 1.06 KB
/
Roman_to_integer_1.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
45
46
47
48
49
50
class Solution:
def romanToInt(self, s):
"""
:type s: str
:rtype: int
"""
result = 0
if 'IV' in s:
result += 4
s = s.replace('IV','')
if 'IX' in s:
result += 9
s = s.replace('IX','')
if 'XL' in s:
result += 40
s = s.replace('XL','')
if 'XC' in s:
result += 90
s = s.replace('XC','')
if 'CD' in s:
result += 400
s = s.replace('CD','')
if 'CM' in s:
result += 900
s = s.replace('CM','')
for i in s:
print(i)
if i == 'M':
result += 1000
elif i == 'D':
result += 500
elif i == 'C':
result += 100
elif i == 'L':
result += 50
elif i == 'X':
result += 10
elif i == 'V':
result += 5
elif i == 'I':
result += 1
return result