Created
October 17, 2019 16:37
-
-
Save staticor/375b26a26046b26b796ebe255f0066ce to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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