双指针算法
class Solution {
public:
int longestSubstringWithoutDuplication(string s) {
if(!s.size()) return 0;
unordered_map<char, int> h;
int res = 0;
for(int i = 0, j = 0; j < s.size(); j ++){
h[s[j]] ++;
if(h[s[j]] > 1){
while(h[s[i]] == 1) h[s[i ++]] --;
i ++;
h[s[j]] = 1;
}
res = max(res, j - i + 1);
}
return res;
}
};