if (s.length() == 1) return map.get(String.valueOf(s.charAt(0))); int sum = 0; int temp = map.get(String.valueOf(s.charAt(0))); int next = 0; int pre = 0; for (int i = 0; i < s.length() - 1; i++) { next = map.get(String.valueOf(s.charAt(i + 1))); pre = map.get(String.valueOf(s.charAt(i))); if (next > pre) { temp = next - temp; } elseif (next == pre) { temp = next + temp; } else { sum = sum + temp; temp = next; } }