Roman to Integer
Question
Answer
solution:this part of the calculation within this code is done by myself.
class Solution(object):
def romanToInt(self, s):
"""
:type s: str
:rtype: int
"""
romans = {'M': 1000, 'D': 500 , 'C': 100, 'L': 50, 'X': 10,'V': 5,'I': 1}
pre = sum = 0
for i in s:
if pre < romans[i]:
sum += -2 * pre + romans[i]
else:
sum += romans[i]
pre = romans[i]
return sumKnowledge:
Last updated