classSolution{publicintromanToInt(String s){Map<Character,Integer> map =newHashMap<>();int sum =0;
map.put('I',1);
map.put('V',5);
map.put('X',10);
map.put('L',50);
map.put('C',100);
map.put('D',500);
map.put('M',1000);if(s.length()==1){return map.get(s.charAt(0));}for(int i =0;i<s.length()-1;i++){char a = s.charAt(i);char b = s.charAt(i+1);if(map.get(a)<map.get(b)){
sum = sum - map.get(a);}else{
sum = sum + map.get(a);}if(i+1== s.length()-1){
sum = sum + map.get(b);}}return sum;}}
罗马数字转整数把罗马数字和对应的阿拉伯数字放在map集合中,从左到右比每一个罗马数字,如果小于则做减法取绝对值,反之相加class Solution { public int romanToInt(String s) { Map<Character,Integer> map = new HashMap<>(); int sum = 0; map.put('I',1); map.put('V',5); map.p