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;
}

浙公网安备 33010602011771号