Given a string, find the length of the longest substring without repeating characters.
class Solution {
public:
int lengthOfLongestSubstring(string s)
{
map<char,int> maps;
int n=s.size();
int index=0;
int result=0;
for(int i=0;i<n;i++)
{
if(maps.find(s[i])!=maps.end()&&maps[s[i]]>=index)
{
index=maps[s[i]]+1;
}
maps[s[i]]=i;
result=max(result,i-index+1);
}
return result;
}
};