```
class Solution {
public:
int lengthOfLongestSubstring(string s)
{
unordered_map<char,int> m;
int len = 0, mx =0;
for(int i=0;i<s.length();)
{
if(m.find(s[i])==m.end())
{
m.emplace(s[i],i);
i++; len++;
if(len>mx) mx=len;
continue;
}
else
{
i = m.find(s[i])->second+1;
len =0;
m.clear();
}
}
return mx;
}
};
```