To iterate through tens of thousands of character data in the oldest string
1. Using the C++11 code
for (auto ch:s) {Auto SS = Vsi[ch];vsi[ch].insert (i); i++;}
2. Using the C++98 code
for (int i = 0; i < s.length (); i++) {ch = s[i];vsi[ch].insert (i);}
The two code time comparisons
1.c++ 11
2.c++ 98
Below is the longest-substring-without-repeating-characters AC code
intLengthoflongestsubstring (strings) {if(S.length () <=1)returns.length (); Vector<Set<int> > vsi ( the); Charch; for(inti =0; I < s.length (); i++) {ch=S[i]; Vsi[ch].insert (i); } intCount =0; intMax =0; for(inti =0; I < s.size ()-1; i++) {Count=0; intEndpos =-1; for(intj = i; J < S.size (); J + +) { if((Endpos! =-1&& J >=endpos)) { Break; } Auto Pos1=Vsi[s[j]].find (j); POS1++; Count++; if(POS1! =Vsi[s[j]].end ()) { intTMP = (*POS1)-i; if(TMP <= Max) Break; if(Endpos > (*pos1) | | endpos = =-1) {Endpos= (*pos1); } } } if(Max <count) {Max=count; } } returnMax;}
C + + vs 98