Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def romanToInt(self, s: str) -> int:
- value = []
- normal = {
- "I": 1,
- "V": 5,
- "X": 10,
- "L": 50,
- "C": 100,
- "D": 500,
- "M": 1000
- }
- notnormal = {
- "IV": 4,
- "IX": 9,
- "XL": 40,
- "XC": 90,
- "CD": 400,
- "CM": 900
- }
- result=0
- i=0
- notnormalb = ''
- while i < len(s):
- if (i + 1) < len(s):
- notnormalb = s[i] + s[i + 1]
- if notnormal.get(notnormalb):
- result += notnormal.get(notnormalb)
- i += 1
- else:
- if normal.get(s[i]):
- result += normal.get(s[i])
- else:
- if normal.get(s[i]):
- result += normal.get(s[i])
- i += 1
- return result
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement