/ * Title: longest substring contain repeated characters. * / / * Idea: F (I) = F (I-. 1) +. 1, (does not appear over the current character, Distance> F (I-. 1) Distance, from the character of a current appears and the characters * / # the include <the iostream> #include <CString> #include <Vector> #include <algorithm> the using namespace STD; int longestSubstringWithoutDuplication (String STR) { int EN [26 is]; Memset (EN, -1, the sizeof (EN)); int str.size = len (); int maxVal = 0; int Curr = 0; for (int I = 0; I <len; I ++) { IF (EN [STR [I] - 'A'] == -1) { Curr + = Curr. 1; } the else { int I = D - EN [STR [I] - 'A']; IF (D> Curr) { curr++; }else{ if(curr > maxVal){ maxVal = curr; } curr = d; } } cout<<str[i]<<" "<<i<<" "<<curr<<endl; en[str[i]-'a'] = i; } return max(curr,maxVal); } int main(){ string str="arabcacfr"; cout<<longestSubstringWithoutDuplication(str); return 0; }