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
猜你喜欢
转载自blog.csdn.net/weixin_40929147/article/details/89282717
今日推荐
周排行