[leetcode 13]Roman to integer
1 题目: Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999. 2 思路 和上一道反过来,好吧,但是思路不一样。 我写的代码思路一样,要考虑一些特殊情况,比较复杂。 别人代码的思路倒是不错: 下面的那个思路,倒序遍历,如果大于5或50或500,那么就是减了,否则就是加。罗马数字小数字在左边是减,且仅限一位。 https://leetcode.com/discuss/2369/solution-for-this-question-but-dont-know-there-any-easier-way 这个是用 哈希函数实现的,我也想过用哈希函数,但是不是这样的,我想的是那个数组全部哈希一遍- -。 https://leetcode.com/discuss/23778/my-accepted-java-code-280-310ms 3 代码: 我的 public int romanToInt(String s) { String[] M = {"","M","MM","MMM"}; String[] C = {"","C","CC","CCC","D","CD","DC","DCC","DCCC","CM"}; String[