public int lengthOfLongestSubstring(String s) {
        if (s == null || s.length() == 0) {
            return 0;
        }
        int start = 0, max = 0;
        HashSet<Character> set = new HashSet<Character>();
        for (int i = 0; i < s.length(); i++) {
            char c =  s.charAt(i);
            if (!set.contains(c)) {
                set.add(c);
                max = Math.max(max, set.size());
                continue;
            }

            while (s.charAt(start) != c) {
                set.remove(s.charAt(start));
                start++;
            }
            start++;
        }
        return max;
    }