双指针
class Solution {
public:
int longestSubstringWithoutDuplication(string s) {
unordered_map<char, int> hash;
int res = 0;
for (int i = 0, j = 0; i < s.size(); i ++ )
{
hash[s[i]] ++ ; //没有重复i就一直增加,j不变
while (hash[s[i]] > 1) //发现重复,j开始追赶i,直到没有重复
hash[s[j ++ ]] -- ;
res = max(res, i - j + 1);
}
return res;
}
};