#include <iostream> #include <string> using namespace std; class Solution { public: int lengthOfLongestSubstring(string s) { int length_substr=0; int temp=0; int hashTable[256]; int i=0; while (i!=256) { hashTable[i]=0; i++; } int j=0; while (s[j]!='\0') { if (hashTable[s[j]]==0) { temp=temp+1; hashTable[s[j]]=1; } else { int k=0; while (k!=256) { hashTable[k]=0; k++; } temp=0; char ch_temp=s[j]; while (1) { j--; if (s[j]==ch_temp) { break; } } } if (temp>length_substr) { length_substr=temp; } j++; } return length_substr; } }; int main() { string str="wlrbbmqbhcdarzowkkyhiddqscdxrjmowfrxsjybldbefsarcbynecdyggxxpklorellnmpapqfwkhopkmco"; Solution sd; int a=sd.lengthOfLongestSubstring(str); cout<<a<<endl; system("pause"); return 0; } </string></iostream>