Roman to Integer
class Solution(object):
def romanToInt(self, s):
"""
:type s: str
:rtype: int
"""
roman = {'M': 1000,'D': 500 ,'C': 100,'L': 50,'X': 10,'V': 5,'I': 1}
result = 0
for i in xrange(len(s)):
result += roman[s[i]]
if i != 0 and roman[s[i]] > roman[s[i-1]]:
result -= 2*roman[s[i-1]]
return resultLast updated