class Solution {
public:
int longestSubstringWithoutDuplication(string s) {
unordered_map<char,int> hash;
int res = 0;
for (int i = 0, j = 0; j < s.size(); j++) {
hash[s[j]] ++;
// 如果s[j]已经在hash中存在,就让s[i]的hash--,i向后移,
// 直到s[j]在hash中不存在为止
while (hash[s[j]] > 1) {
hash[s[i]] --;
i++;
}
res = max(res, j - i + 1);
}
return res;
}
};