Skip to content

Instantly share code, notes, and snippets.

@staticor
Created October 17, 2019 16:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save staticor/375b26a26046b26b796ebe255f0066ce to your computer and use it in GitHub Desktop.
Save staticor/375b26a26046b26b796ebe255f0066ce to your computer and use it in GitHub Desktop.
class Solution:
def romanToInt(self, s: str) -> int:
d = {'I':1, 'IV':3, 'V':5, 'IX':8, 'X':10, 'XL':30, 'L':50, 'XC':80, 'C':100, 'CD':300, 'D':500, 'CM':800, 'M':1000}
return sum(d.get(s[max(i-1, 0):i+1], d[n]) for i, n in enumerate(s))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment