class Solution:

```
def romanToInt(self, s):
"""
:type s: str
:rtype: int
"""
d = {'I': 1, 'V' : 5, 'X' : 10, 'L' : 50, 'C' : 100, 'D' : 500, 'M' : 1000}
sum = 0;
pre = 0
for i in s:
if pre < d[i] :
sum -= pre * 2
sum += d[i];
pre = d[i];
return sum
```