class Solution:
def romanToInt(self, s: str) -> int:
a = {'I':1, 'V':5, 'X':10, 'L':50, 'C':100, 'D':500, 'M':1000}
count=0
l=list(s)
for i in range(len(l)):
if i<len(l)-1 and a[l[i]]<a[l[i+1]]:
count-=a[l[i]]
else:
count+=a[l[i]]
return count
leetcode罗马数字转换 13
最新推荐文章于 2024-04-06 21:46:54 发布