@@ -0,0 +1,1355 @@
+// Solution 1: use map (performance is better)%0Apublic class Solution %7B%0A    public int lengthOfLongestSubstring(String s) %7B%0A        int max = 0;%0A        Map%3CCharacter, Integer%3E position = new HashMap%3CCharacter, Integer%3E();%0A        %0A        for(int start = 0, end = 0; end %3C s.length(); end++) %7B%0A            char c = s.charAt(end);%0A            if(position.containsKey(c)) %7B%0A                // other characters less than the repeating character are no long useful%0A                // if the string is %22abcaabcd%22, when we look at 3rd 'a', all other characters before 2nd 'a' are not considered%0A                start = Math.max(start, position.get(c) + 1);%0A            %7D%0A            position.put(c, end);%0A            max = Math.max(max, end - start + 1);%0A        %7D%0A        return max;%0A    %7D%0A%7D%0A%0A// Solution 2: use set (solution is worse)%0Apublic class Solution %7B%0A    public int lengthOfLongestSubstring(String s) %7B%0A        int start = 0, end = 0, max = 0;%0A        Set%3CCharacter%3E substring = new HashSet%3CCharacter%3E();%0A        %0A        while(end %3C s.length()) %7B%0A            if(!substring.contains(s.charAt(end))) %7B%0A                substring.add(s.charAt(end++));%0A                max = Math.max(max, substring.size());%0A            %7D%0A            else %7B%0A                substring.remove(s.charAt(start++));%0A            %7D%0A        %7D%0A        %0A        return max;%0A    %7D%0A%7D%0A

Create LongestSubstringWithoutRepeatingCharacters.java