3. Longest Substring Without Repeating Characters


    public int lengthOfLongestSubstring(String s) {
        int max = 1;
        int start = 0;
        int end = 1;
        
        int len = s.length();
        if(len == 0) return 0;
        
        int[] countTable = new int[256];
        Arrays.fill(countTable,-1);
        
        countTable[s.charAt(0)] = 0;
        while(end<len){
            if(countTable[s.charAt(end)] >= start){
                start = 1 + countTable[s.charAt(end)];
            }
            max = Math.max(max,end - start +1);
            countTable[s.charAt(end)] = end;
            end ++;
        }
        return max;
        
 
    }
posted @ 2016-07-08 16:03  Zhou_SYSU  阅读(93)  评论(0)    收藏  举报