13. 罗马数字转整数
https://leetcode-cn.com/problems/roman-to-integer/
解法一:左加右减
这个思路很6,根据罗马数字的左加右减法则,比较s[i]和s[i+1]所表示的数字大小,若s[i]<s[i+1],则res减去s[i],否则res加上s[i]
先将s转换成相应数字,再比较,省去了查dict的时间,速度更快
最后更新于
https://leetcode-cn.com/problems/roman-to-integer/
这个思路很6,根据罗马数字的左加右减法则,比较s[i]和s[i+1]所表示的数字大小,若s[i]<s[i+1],则res减去s[i],否则res加上s[i]
先将s转换成相应数字,再比较,省去了查dict的时间,速度更快
最后更新于