1. 程式人生 > >leetcode 13 -> Roman to Integer

leetcode 13 -> Roman to Integer

def bsp div ast solution lis etc bject val

class Solution(object):
    def romanToInt(self, s):
        """
        :type s: str
        :rtype: int
        """
        lista={I:1,V:5,X:10,L:50,C:100,D:500,M:1000}
        Value_sum=0
        last_Value=0
        for i in range(len(s)):
            if (lista[s[i]] in [1,10,100]) and ( last_Value not in
[1,10,100]): Value_sum=Value_sum+lista[s[i]] elif (last_Value in [1,10,100]) and (last_Value<lista[s[i]]): Value_sum=Value_sum+lista[s[i]]-2*last_Value else: Value_sum=Value_sum+lista[s[i]] last_Value=lista[s[i]]
return Value_sum

leetcode 13 -> Roman to Integer