滑动窗口
我真傻啊!!
class Solution {
//滑动窗口
public int lengthOfLongestSubstring(String s) {
char[] c =s.toCharArray();
int start = 0,end = 0,max = 0;
int flag = 0;
while(end< c.length){
flag = findRep(c,start,end);
if(flag != -1){
start = flag+1;
}
//更新max
max = max > (end - start +1)?max:end-start+1;
end++;
}
return max;
}
//有重复返回索引,无重复返回-1;
public int findRep(char[] c,int start,int end){
char t = c[end];
for(int i = start;i<end;i++){
if(t==c[i]) return i;
}
return -1;
}
}