class Solution:
# @return an integer
def lengthOfLongestSubstring(self, s):
len = 0
maxLen = 0
arr = list(s)
for index,i in enumerate(arr):
if i not in arr[indexlen:index]:
len +=1
else:
maxLen = max(maxLen,len)
len = index  (arr[indexlen:index].index(i) + indexlen)
return max(maxLen,len)
My O(n) Solution


I think the solution is not O(n).
"i not in arr[indexlen:index]" is an O(n) operation. Therefore, for example, in the extreme case of the longest substring is the string itself, the "not in" step takes 1, 2, 3, ..., n in each iteration, so the for loop actually takes O(n^2).
Correct me if I'm wrong.