class Solution {
public:
int lengthOfLongestSubstring(string s) {
int n=s.size();
int cnt[256]={0};
int i=0, j=0, ans=0;
while(j<n)
{
cnt[s[j]]++;
while(cnt[s[j]]>1)
{
cnt[s[i]]--;
i++;
}
ans=max(ans, j-i+1);
j++;
}
return ans;
}
};