title: optimaze my solution : find the length of the longest substring without repeating characters
body: <p>In a Leetcode question I'm asket to find the length of the longest substring without repeating characters.
  for example:</p>
  <pre><code>Input: s = &quot;abcabcbb&quot;
  Output: 3
  Explanation: The answer is &quot;abc&quot;, with the length of 3.
  </code></pre>
  <p>and this is what I did:</p>
  <pre><code>
  class Solution:
      def lengthOfLongestSubstring(self, s: str) -&gt; int:
              if len(s)==0:
                  return 0
              
              else:
                      lenghts=[]
                      subs=[]
                      #find all the substrings with two loops
                      for i in range(len(s)):
                          for j in range(i+1,len(s)+1):
                                subs.append(s[i:j])
  
                      for sub in subs:
                           #check if the substring has repeated characters, if not append its lenght to the list lenghts
                          if len(set(sub))==len(sub):
                              lenghts.append(len(sub))
  
  
                      return max(lenghts)
  
  </code></pre>
  <p>the problem is that the solution passes 986/987 test cases, which means I have to improve it.
  I thought of changing the way of finding the list of substrings to avoid the time comlexity O(n2), but I don't know how to do it.</p>