class Solution {
public:
int lengthOfLongestSubstring(string s) {
if(s.empty())
return 0;
int ans = 1;
size_t beg = 0, end = 1;
vector<bool> visited(256, false);
visited[s[0]] = true;
while(end < s.size())
{
if(visited[s[end]])
{
while(1)
{
visited[s[beg]] = false;
if(s[beg++] == s[end])
break;
}
}
visited[s[end++]] = true;
if(end - beg > ans)
ans = end - beg;
}
return ans;
}
};