Leetcode brushing record-13. Roman numbers to integers

Insert picture description here
Insert picture description here
I don't know what this question is about. . . .

class Solution:
    def romanToInt(self, s: str) -> int:
        thisdict = {
            'I':1,
            'V':5,
            'X':10,
            'L':50,
            'C':100,
            'D':500,
            'M':1000,
            'IV':4,
            'IX':9,
            'XL':40,
            'XC':90,
            'CD':400,
            'CM':900
        }
        res = 0
        allposs = ['IV','IX','XL','XC','CD','CM','I','V','X','L','C','D','M']
        for poss in allposs:
            while poss in s:
                res += thisdict[poss]
                s = s.replace(poss,'',1)
        return res
Published 59 original articles · Liked 14 · Visitors 20,000+

Guess you like

Origin blog.csdn.net/weixin_41545780/article/details/105475126