class Solution:
def romanToInt(self, s: str) -> int:
roman_dict = {
'M':1000,
'D':500,
'C':100,
'L':50,
'X':10,
'V':5,
'I':1
}
count = 0
for i in range(len(s)-1):
if roman_dict[s[i]] < roman_dict[s[i+1]]:
count -= roman_dict[s[i]]
else:
count += roman_dict[s[i]]
count += roman_dict[s[-1]]
return count
13,罗马数字转整数
最新推荐文章于 2021-12-15 23:16:45 发布