Python2 simple solution by Joey簡單解法

  • 0

    By using same concept as int to Roman, because we read Roman from left to right, so we evaluate it by check if the string is in the index 0. Using find() function is much simple.

    decimal = [1000,900,500,400,100,90,50,40,10,9,5,4,1]
    roman = ['M','CM','D','CD','C','XC','L','XL','X','IX','V','IV','I']
    ans = 0
    for i in range(len(decimal)):
        while s.find(roman[i])==0:
            ans += decimal[i] 
    return ans

Log in to reply

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