//"最长连续不重复子序列"的哈希解法
class Solution {
public:
int longestSubstringWithoutDuplication(string s) {
unordered_map<char,int> count;
int res = 0;
for(int i=0,j=0;i<s.size();i++){
count[s[i]]++;
while(j<i && count[s[i]] > 1){
count[s[j]]--;
j++;
}
res = max(res,i-j+1);
}
return res;
}
};
用哈希存储遍历到的元素