Given a Roman numeral, convert it to an integer.
Input is guaranteed to being within the range from 1 to 3999.
1 Public classSolution {2 Public intRomantoint (String s) {3 intRes=0;4hashmap<string, integer> map =NewHashmap<string, integer>();5Map.put ("M", +); Map.put ("CM", "Map.put"); Map.put ("CD", 400);6Map.put ("C", +); Map.put ("XC", 90);7Map.put ("L", "X"), Map.put ("XL", "9"), Map.put ("X.", "Map.put"), Map.put ("IX"), 5 ("V"););8Map.put ("IV", 4); Map.put ("I", 1);9 if(S.equals (""))return0;Ten if(S.length () ==1)returnMap.get (s); One String SS; A for(inti = 0; I < s.length (); i++) { - if(I<s.length ()-1) { -SS = S.substring (i, i + 2); the}Else { -SS = S.substring (i, i + 1); - } - + if(Map.containskey (ss)) { -res = res +Map.get (ss); +++i; A}Else { atSS = S.substring (i, i + 1); -res = res +Map.get (ss); - } - } - returnRes; - } in}
Leetcode Roman to Integer