public int lengthOfLongestSubstring(String s) {
        if (s.length() == 0)
            return 0;
        HashMap<Character, Integer> hash_map = new HashMap<Character, Integer>();
        int ptr = 0, max = 0;
        for (int i = 0; i < s.length(); ++i) {
            char c = s.charAt(i);
            if (hash_map.containsKey(c) && hash_map.get(c) >= ptr) {
                ptr = hash_map.get(c) + 1;
            }
            hash_map.put(c, i);
            max = Math.max(i - ptr + 1, max);
        }
        return max;
    }