Blow is my C# solution for your reference

```
if (s.Length <= 1)
return s.Length;
int maxlen = 0;
for (int i = 0, j = 1, len = 0; j < s.Length; j++)
{
string sub = s.Substring(i,j-i);
len = sub.Length;
int f = sub.IndexOf(s[j]);
if (f>=0)
i += f + 1;
else
len += 1;
maxlen = len > maxlen ? len : maxlen;
}
return maxlen;
```