罗马数字转整数
题目
lettcode-13题
难度:简单
解题思路
对于每个罗马符号所对应的数值,我们可以将其用一个HashMap存起来,将其字符作为key,以及数值为相应的value
在方法中对输入的字符串的所有字符进行遍历,get到所对应的值,并拿到它的后一位数的值,如果当前符号的值大于后一位符号的值,则进行+运算,否则-运算。
具体代码
1 | //leetcode项目 |
lettcode-13题
难度:简单
对于每个罗马符号所对应的数值,我们可以将其用一个HashMap存起来,将其字符作为key,以及数值为相应的value
在方法中对输入的字符串的所有字符进行遍历,get到所对应的值,并拿到它的后一位数的值,如果当前符号的值大于后一位符号的值,则进行+运算,否则-运算。
1 | //leetcode项目 |