title: How to find longest substring without repeating characters?
body: <p>I am solving a problem on leetcode.Here is the question link<br>
  <a href="https://leetcode.com/problems/longest-substring-without-repeating-characters/" rel="nofollow noreferrer">https://leetcode.com/problems/longest-substring-without-repeating-characters/</a></p>
  
  <p>Below is my solution which is not passing some test-cases:</p>
  
  <ol>
  <li>abcabcbb -- not correct</li>
  <li>pwwkew -- correct</li>
  <li>bbbbb -- not correct</li>
  </ol>
  
  <p>Any help would be thankful:)<br>
  And also I am a newbie here so you can suggest me about my problem statement.</p>
  
  <pre><code>class Solution {
      public int lengthOfLongestSubstring(String s) {
  
          int i,max=0;
          List&lt;Character&gt; list = new ArrayList&lt;&gt;();
          String x = "";
          for(i=0;i&lt;s.length();i++)
          {
              if(!list.contains(s.charAt(i)))
              {
                  x += s.charAt(i);
                  list.add(s.charAt(i));
                   System.out.println(x);
              }
              else
              {
                  if(x != null &amp;&amp; x.length() &gt; max)
                  {
                      max = x.length();     
                      System.out.println(max);
                      x = "";
                      list.clear();
                      System.out.println("x : "+ x);
                      System.out.println("list : "+ list);
                  } 
                  // else
                  // {
                  //     list.add(s.charAt(i));
                  //     x += s.charAt(i);    
                  //     System.out.println("x in else : "+ x);
                  //     System.out.println("list in else : "+ list);
                  // }
                  list.add(s.charAt(i));
                  x += s.charAt(i); 
                  System.out.println("x in else : "+ x);
                  System.out.println("list in else : "+ list);
              }
          }
          return max;
      }
  }
  </code></pre>