class Solution {

public:

int lengthOfLongestSubstring(string s)

{

int index = 0;

int max = 0,k = 0,count = 0;

bool flag = true;

int len = s.length();

if( len == 0)

return 0;

if (len ==1)

return 1;

int m = s[0];

while(s[k] != '\0')

{

if(m == s[++k])

{

flag = false;

count++;

}

else

flag = true;

if(flag)

break;

}

if(count == (len-1))

return 1;

for (int i =1; i< len; i++)

{

for(int j=i-1; j>=index; j--)

{

if(s[i] == s[j])

{

index = j+1;

break;

}

else

{

if(max < i-j+1)

max = i - j +1;

}

}

}

return max;

}

};