classSolution { public: intlengthOfLongestSubstring(strings) { intleft=0;intright=0;intans=0; intn=s.size(); unordered_set<char>hashset; for(left=0;left<n;left++){ while(right<n&&hashset.count(s[right])==0){ hashset.insert(s[right]); ans=max(ans,right-left+1); ++right; } hashset.erase(s[left]); } returnans; } };