MCPcopy Create free account
hub / github.com/Jack-Lee-Hiter/AlgorithmsByPython / romanToInt

Method romanToInt

leetcode/13. Roman to Integer.py:10–19  ·  view source on GitHub ↗
(self, s)

Source from the content-addressed store, hash-verified

8
9class Solution(object):
10 def romanToInt(self, s):
11 romanDict = {'M':1000, 'D':500, 'C':100, 'L':50, 'X':10, 'V':5, 'I':1}
12 res, p = 0, 'I'
13 for ch in s[::-1]:
14 if romanDict[ch] < romanDict[p]:
15 res = res - romanDict[ch]
16 else:
17 res = res + romanDict[ch]
18 p = ch
19 return res
20
21s = Solution()
22print((s.romanToInt("IX")))

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected