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]]++;
while (hash[s[i]] > 1 && j < i) hash[s[j++]]--;
res = max(res, i - j + 1);
}
return res;
}
};