Skip to content

Commit dd720cf

Browse files
committed
committed from zkp
1 parent f8e649d commit dd720cf

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

LeetCode/romanToInt.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution:
2+
def romanToInt(self, s):
3+
"""
4+
:type s: str
5+
:rtype: int
6+
"""
7+
L = {'I': 1, "IV": 4, 'V': 5, "IX": 9, "X": 10, "XL": 40, "L": 50, "XC": 90, "C": 100, "CD": 400, "D": 500,
8+
"CM": 900, "M": 1000}
9+
n = 0
10+
while s:
11+
i = 2
12+
if s[:i] not in L:
13+
i -= 1
14+
n += L[s[:i]]
15+
s = s[i:]
16+
return n

0 commit comments

Comments
 (0)