LeetCode 3
题目复述:求一字符串中不重复的连续最长字符子串长度
class Solution {
public:
int lengthOfLongestSubstring(string s) {
unordered_set<char> temp;
int n=s.size();
int rr=-1,lenMax=0;
for(int i=0;i<n;i++){
if(i!=0){
temp.erase(s[i-1]);
}
while(rr+1<n&&!temp.count(s[rr+1])){
temp.insert(s[rr+1]);
++rr;
}
lenMax=max(lenMax,rr-i+1);
}
return lenMax;
}
};