Plus all value of char which are greater than next one, and minus all value of char while are less than next one. Of course, the final one to be added.

class Solution(object):

def romanToInt(self, s):

"""

:type s: str

:rtype: int

"""

dic = { 'M' : 1000, 'D' : 500, 'C' : 100, 'L' : 50, 'X' : 10, 'V' : 5, 'I' : 1}

x = 0

for i in range(len(s)):

if i == len(s) - 1 or dic[s[i]] >= dic[s[i + 1]]:

x += dic[s[i]]

else:

x -= dic[s[i]]

return x