Skip to content

Commit ee8458b

Browse files
authored
Create 13-Roman-To-Integer.py
1 parent a57cafd commit ee8458b

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

13-Roman-To-Integer.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution:
2+
def romanToInt(self, s: str) -> int:
3+
roman = { "I" : 1, "V" : 5, "X" : 10,
4+
"L" : 50, "C" : 100, "D" : 500, "M" : 1000 }
5+
res = 0
6+
for i in range(len(s)):
7+
if i + 1 < len(s) and roman[s[i]] < roman[s[i + 1]]:
8+
res -= roman[s[i]]
9+
else:
10+
res += roman[s[i]]
11+
return res

0 commit comments

Comments
 (0)