Python Solution for Roman to Integer


  • 0
    A

    ...
    class Solution:
    def romanToInt(self, s):
    """
    :type s: str
    :rtype: int
    """
    romannum={'I':1,'V':5,'X':10,'L':50,'C':100,'D':500,'M':1000}
    temps=[romannum[i] for i in s]
    index=len(temps)-1
    while index>=0:
    a=1
    while a<=index:
    if (temps[index]-temps[index-a])>0:
    temps[index-a]=~temps[index-a]+1
    a=a+1
    index=index-1
    result=0
    print(temps)
    for i in temps:
    result=result+i
    return result
    ...


Log in to reply
 

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