very熟练了可以说是
好开心诶 再写一题吧
class Solution {
public:
int lengthOfLongestSubstring(string s) {
unordered_set<char> sub;
int l=0,r=0,len=s.size(),ans=0,tmp=0;
while(r<len){
if(sub.count(s[r])){sub.clear();tmp=0;l+=1;r=l;}
else{tmp+=1; if(ans<tmp) ans=tmp;sub.insert(s[r]);r++;}
}
return ans;
}
};