class Solution {
public:
int lengthOfLongestSubstring(string s) {
unordered_set<char> us;
int n = s.size(), l = 0, r = 0, maxLen = 0;
while(r < n){
while(r < n && us.find(s[r]) == us.end())
us.insert(s[r++]);
maxLen = max(maxLen, r-l);
us.erase(s[l++]);
}
return maxLen;
}
};