题目链接:
https://leetcode.com/problems/roman-to-integer/
思路:
用HashMap类,用字符型作为key,其对应的数为value。当一个字符代表的数小于其后一个字符代表的数时,这个数等于后一个字符代表的数减去该字符代表的数,否则等于二者相加。用HashMap是因为不需要思考如何遍历,直接找到Key就行。
Solution:
1 | class Solution { |
题目链接:
https://leetcode.com/problems/roman-to-integer/
思路:
用HashMap类,用字符型作为key,其对应的数为value。当一个字符代表的数小于其后一个字符代表的数时,这个数等于后一个字符代表的数减去该字符代表的数,否则等于二者相加。用HashMap是因为不需要思考如何遍历,直接找到Key就行。
Solution:
1 | class Solution { |