1class py_solution:
2 def roman_to_int(self, s):
3 rom_val = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000}
4 int_val = 0
5 for i in range(len(s)):
6 if i > 0 and rom_val[s[i]] > rom_val[s[i - 1]]:
7 int_val += rom_val[s[i]] - 2 * rom_val[s[i - 1]]
8 else:
9 int_val += rom_val[s[i]]
10 return int_val
11
12print(py_solution().roman_to_int('MMMCMLXXXVI'))
13print(py_solution().roman_to_int('MMMM'))
14print(py_solution().roman_to_int('C'))
15
16