Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. For "bbbbb" the longest substring is "b", with the length of 1.
#include <iostream>
#include <vector>
#include <string>
using namespace std;
string ss="le34eeelfdshdsofjjwjwlajajadmxcml;df,xzmKdhndkjdlasjsmxnalamsasjaeeee";
string sub;
void findLongestSubstring(){
int from=0,to=1;
int tempFrom=0,tempTo=1;
char tempChar;
for (int i = 1; i < ss.size(); ++i){
sub=ss.substr(tempFrom,tempTo);
tempChar=ss.at(i);
// tempTo=i;
if(sub.find(tempChar)!=-1){//包含字符
// to=i-1;
if((tempTo)>(to)){
to=tempTo;
from=tempFrom;
}
tempFrom+=sub.find(tempChar)+1;
tempTo=i-tempFrom+1;
}
else{
++tempTo;
}
if(i==ss.size()-1){
if((tempTo)>(to)){
to=tempTo;
from=tempFrom;
}
}
}
sub=ss.substr(from,to);
cout<<sub;
}
int main(){
findLongestSubstring();
// cout<<sub;
}