Given a roman numeral, convert it to an integer.
Input is guaranteed to be within the range from 1 to 3999.
My code:
class Solution(object):
def romanToInt(self, s):
"""
:type s: str
:rtype: int
"""
numDict = {'I':1,'V':5,'X':10,'L':50,'C':100,'D':500,'M':1000}
subList=['I','X','C']
result = numDict[s[len(s)-1]]
for i in range(len(s)-2,-1,-1):
if numDict[s[i]] < numDict[s[i+1]] and s[i] in subList :
result -= numDict[s[i]]
else :
result += numDict[s[i]]
return result