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