测试 0
class Solution {
public:
int lengthOfLongestSubstring(string s) {
int cnt = 0;
int l=0,r=0;
while(r<s.size()){
for(int i=l;i<r;i++){
if(s[i]==s[r]){
l = i+1;
break;
}
}
cnt = max(cnt,r-l+1);
r++;
}
return cnt;
}
};
测试 1
class Solution {
public:
int lengthOfLongestSubstring(string s) {
int cnt = 0;
int l=0,r=0;
while(r<s.size()){
for(int i=l;i<r;i++){
if(s[i]==s[r]){
l = i+1;
break;
}
}
cnt = max(cnt,r-l+1);
r++;
}
return cnt;
}
};
测试 3
class Solution {
public:
int lengthOfLongestSubstring(string s) {
int cnt = 0;
int l=0,r=0;
while(r<s.size()){
for(int i=l;i<r;i++){
if(s[i]==s[r]){
l = i+1;
break;
}
}
cnt = max(cnt,r-l+1);
r++;
}
return cnt;
}
};
测试 4
class Solution {
public:
int lengthOfLongestSubstring(string s) {
int cnt = 0;
int l=0,r=0;
while(r<s.size()){
for(int i=l;i<r;i++){
if(s[i]==s[r]){
l = i+1;
break;
}
}
cnt = max(cnt,r-l+1);
r++;
}
return cnt;
}
};