publicclassSolution {publicintromanToInt(String s) {if (s ==null||s.length() ==0) {return0; }Map<Character,Integer> map =newHashMap<Character,Integer>();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);int len =s.length();int num =map.get(s.charAt(len -1));for (int i = len -2; i >=0; i--) {if (map.get(s.charAt(i +1)) <=map.get(s.charAt(i))) { num +=map.get(s.charAt(i)); } else { num -=map.get(s.charAt(i)); } }return num; }}