class Solution {
public:
int lengthOfLongestSubstring(string s) {
int num = 0, i = 0, j = 0, index = 0, len = 0;
len = s.length();
if(len==0) return 0;
if(len==1) return 1;
for(int i=1; i<len; i++){ //i要从1开始
for(int j=i-1; j>=index; j--){
if(s[i]==s[j]){
index = j+1;
break;
}else{
num = max(num, i-j+1);
}
}
}
return max(num, 1); //处理防止出现 bbbb这样的case
}
};
leetcode+3. Longest Substring Without Repeating Characters+滑动窗口
最新推荐文章于 2024-11-02 14:05:28 发布