滑动窗口法
class Solution {
public:
int lengthOfLongestSubstring(string s) {
int left = 0;
int right = 0;
int maxlen = 0;
set<char> window;
while(right < s.size()){
while(window.find(s[right]) != window.end()){
window.erase(s[left]);
left++;
}
maxlen = max(maxlen, right-left+1);
window.insert(s[right++]);
}
return maxlen;
}
};