We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 01cb3d8 commit 43afb18Copy full SHA for 43afb18
leetcode-013/leetcode013.py
@@ -0,0 +1,26 @@
1
+class Solution:
2
+ def romanToInt(self, s: str) -> int:
3
+ d = dict()
4
+ d = {
5
+ 'I': 1,
6
+ 'V': 5,
7
+ 'X': 10,
8
+ 'L': 50,
9
+ 'C': 100,
10
+ 'D': 500,
11
+ 'M': 1000
12
+ }
13
+
14
+ sum0 = 0
15
+ for i in range(len(s)):
16
+ currentValue = d[s[i]]
17
18
+ if i == len(s) -1 or d[s[i+1]] <= currentValue: # d[s[i+1]]: nextValue
19
+ sum0 += d[s[i]]
20
+ else:
21
+ sum0 -= d[s[i]]
22
23
+ return sum0
24
25
+sol = Solution()
26
+print(sol.romanToInt("MCMXCIV"))
0 commit comments