classSolution: defromanToInt(self, s: str) -> int: i = 0 sum = 0 while(i < len(s)): if(s[i] == "I"): if(i + 1 < len(s)): if(s[i+1] == "V"): sum = sum + 4 i = i + 2 elif(s[i+1] == "X"): sum = sum + 9 i = i + 2 else: sum = sum + 1 i = i + 1 else: sum = sum + 1 i = i + 1 elif(s[i] == "X"): if(i + 1 < len(s)): if(s[i+1] == "L"): sum = sum + 40 i = i + 2 elif(s[i+1] == "C"): sum = sum + 90 i = i + 2 else: sum = sum + 10 i = i + 1 else: sum = sum + 10 i = i + 1 elif(s[i] == "C"): if(i + 1 < len(s)): if(s[i+1] == "D"): sum = sum + 400 i = i + 2 elif(s[i+1] == "M"): sum = sum + 900 i = i + 2 else: sum = sum + 100 i = i + 1 else: sum = sum + 100 i = i + 1 elif(s[i] == "V"): sum = sum + 5 i = i + 1 elif(s[i] == "L"): sum = sum + 50 i = i + 1 elif(s[i] == "D"): sum = sum + 500 i = i + 1 elif(s[i] == "M"): sum = sum + 1000 i = i + 1 returnsum