class Solution {
Map<Character, Integer> maps = new HashMap<>(){{
put('I', 1);
put('V', 5);
put('X', 10);
put('L', 50);
put('C', 100);
put('D', 500);
put('M', 1000);
}};
public int romanToInt(String s) {
int sum = 0;
int val = 0;
for(int i=0;i<s.length();++i){
val = maps.get(s.charAt(i));
/**小于右边且右边存在则减
否则就是大于右边则加
*/
if( i < s.length()-1 && val < maps.get(s.charAt(i+1))){
sum = sum - val;
}else{
sum = sum + val;
}
}
return sum;
}
}