滑动窗口
class Solution {
public:
int longestSubstringWithoutDuplication(string s) {
unordered_map<char, int> window;
int left = 0, right = 0, res = 0;
while(right < s.size()) {
char c = s[right++];
window[c]++;
while(window[c] > 1) {
char d = s[left++];
window[d]--;
}
res = max(res, right-left);
}
return res;
}
};