https://oj.leetcode.com/problems/roman-to-integer/
Http://fisherlei.blogspot.com/2012/12/leetcode-roman-to-integer.html
symbolvalue// i1// v5// x10// l50// c100// d500// m1,000public class solution { public int romantoint (String s) { Map< Character, integer> map = new hashmap<> (); 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); char[] chars&nBsp;= s.tochararray (); character lastchar = null; int toReturn = 0; for (int i = 0 ; i < chars.length ; i ++) { char curChar = chars[i]; int curvalue = map.get (CurChar); integer lastvalue = lastchar == null ? null : map.get (Lastchar); if (lastvalue == null | | lastvalue >= curvalue) { toReturn += curValue; } else { // Last char is wrong toReturn -= lastValue; toReturn += (Curvalue - lastvalue); } lastchar = curchar; } return toReturn; }}
[Leetcode]13 Roman to Integer