We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent a57cafd commit ee8458bCopy full SHA for ee8458b
13-Roman-To-Integer.py
@@ -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