I don't think it can get any faster than this:
class Solution:
def lengthOfLongestSubstring(self, S):
for i in xrange(len(S) - 1, 0, -1):
for j in xrange(len(S) - i):
s = S[j : j + i + 1]
if len("".join(set(s))) == len(s):
return len(s)
return 1
However, I am exceeding the time limit. What am I doing wrong?