13. Roman to Integer
https://leetcode.com/problems/roman-to-integer/description/
Last updated
Was this helpful?
https://leetcode.com/problems/roman-to-integer/description/
Last updated
Was this helpful?
Given a roman numeral, convert it to an integer.
Input is guaranteed to be within the range from 1 to 3999.
罗马数字转成整形。转换规则是遇到M, D, C, L, X, V和I分别加1000, 500, 100, 50, 10, 5, 1. str中如果有 IV, IX, XL, XC,CD和CM再分别减去2, 2, 20, 20, 200和200。除了按照以上规则hard code外还可以倒着处理,当遇到值比下一位低的做减法,否则加。
参考了。
时间复杂度O(N).