[LeetCode] 13. Roman to Integer
Python
class Solution:
def romanToInt(self, s: str) -> int:
temps = {
"I": 1,
"V": 5,
"X": 10,
"L": 50,
"C": 100,
"D": 500,
"M": 1000}
answer = 0
past = 'I'
for current in s[::-1]:
if temps[current] < temps[past]:
answer -= temps[current]
else:
answer += temps[current]
past = current
return answer
댓글남기기