I am trying to solve this Leetcode problem, without using Sets
https://leetcode.com/problems/longest-substring-without-repeating-characters/
The way im tackling it is by stopping at every element in the list and going one element right until i find a duplicate, store that as the longest subset without duplication and continuing with the next element to do it again.
I'm stuck because i cant find a way to iterate the whole list at every element
Below is what i have so far
def lengthOfLongestSubstring(self, s):
mylist = list(s)
mylist2 = list(s)
final_res = []
res = []
for i in mylist2:
for char in mylist:
if char in res:
res=[]
break
else:
res.append(char)
if len(res) > len(final_res):
final_res = res
return final_res