class Solution {
public:
int lengthOfLongestSubstring(string s) {
int count=0;
int max=0;
int k=0;
vector<char> temp;
for(int i=0;i<s.size();i++){
for(int j=k;j<temp.size();j++){
if(s[i]==temp[j]){
k = j + 1;
if(max<count)
max = count;
count = temp.size() - k;
break;
}
}
count++;
if(max<count)
max = count;
temp.push_back(s[i]);
}
return max;
}
};
//循环遍历较复杂,可考虑用哈希表
Longest Substring Without Repeating Characters
最新推荐文章于 2019-11-12 16:24:00 发布