class Solution {
public:
//l字符串匹配,KMP算法
int lengthOfLongestSubstring(string s) {
int len=s.length();
if(len==0){
return 0;
}
int i=0;
int j=1;
int cur_max=0;
while(j<len&&i<len){
int fla=1;
int tmp;
for(int k=i;k<j;k++){
if(s[k]==s[j]){
fla=0;
tmp=k;
break;
}
}
if(fla==0){
i=tmp+1;
j++;
}else{
j++;
if(j-i>cur_max){
cur_max=j-i;
}
}
}
if(cur_max==0){
cur_max=1;
}{
}
return cur_max;
}
};