class Solution {
public:
int longestSubstringWithoutDuplication(string s) {
if(!s.length()) return 0;
int res = 1, i = 0, j = 0;
bool tag[27] = {false};
while (i < s.length() && j < s.length())
{
while(j < s.length() && !tag[s[j] - 'a'])
{
tag[s[j++] - 'a'] = true;
}
res = max(res, j-i);
while(i < s.length() && s[i] != s[j])
{
tag[s[i++] - 'a'] = false;
}
i++ & j++;
}
return res;
}
};