public int romanToInt(String s) {
if (s == null || s.isEmpty()) {
return 0;
}
Map<Character, Integer> hm = new HashMap<>();
hm.put('I', 1);
hm.put('V', 5);
hm.put('X', 10);
hm.put('L', 50);
hm.put('C', 100);
hm.put('D', 500);
hm.put('M', 1000);
int res = 0;
for (int i = 0; i < s.length(); i++) {
int cur = hm.get(s.charAt(i));
if (i == s.length() - 1 || hm.get(s.charAt(i + 1)) <= cur ) {
res += cur;
} else {
res -= cur;
}
}
return res;
}