Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "ABCABCBB" are "abc", which the length is 3. For "bbbbb" the longest substring are "B", with the length of 1.
Thinking of solving problems
Set the left and right two pointers, and the left hand pointer is not duplicated, and the correct pointer moves to the right, otherwise it moves to the right (until there are no repeating characters), and the maximum number of characters is counted.
Implementation code
//rumtime:60 MSclassSolution { Public:intLengthoflongestsubstring (strings) { Set<int>ResintMaxLen =0;intleft =0;intI for(i =0; I < s.size (); i++) {if(Res.find (s[i])! = Res.end ()) {maxlen = max (MaxLen, i-left); while(S[left]! = S[i]) {res.erase (s[left++]); } left++; }Else{Res.insert (s[i]); }} maxlen = Max (MaxLen, i-left);returnMaxLen; }};
[Leetcode] Longest Substring without repeating characters