Short n Simple Python


  • 0
    E
        def romanToInt(self, s):
            """
            :type s: str
            :rtype: int
            """
            memo, val = {'I':1,'V':5,'X':10,'L':50,'C':100,'D': 500,'M':1000}, 0
            for i,v in enumerate(s):
                val += -memo[v] if memo[s[min(len(s)-1,i+1)]] > memo[v] else memo[v]
            return val
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.