package problems;

import java.util.HashMap;

public class LongestSubstringWORepeating {
    public int lengthOfLongestSubstring(String s) {
        int len = s.length();
        int l = 0, r = 0;
        int max = 0; // max length
        HashMap<Character, Character> hs = new HashMap<Character, Character>();

        char c = 0, d = 0;
        for (r = 0; r < len; r++) {
            c = s.charAt(r);
            if (!hs.containsKey(c)) { // no such char in substring yet
                hs.put(c, c);
            } else { // char repeat
                if (r - l > max)
                    max = r - l;
                while ((d = s.charAt(l)) != c) { // search the repeat one
                    hs.remove(d);
                    l++;
                }
                l++; // go to the first non-repeat one
            }
        }
        if (r - l > max)
            max = r - l;

        return max;
    }

    public static void main(String[] args) {
        LongestSubstringWORepeating ls = new LongestSubstringWORepeating();

        String s = "abcabcdbb";
        int a = ls.lengthOfLongestSubstring(s);
        System.out.println(a);
    }
}

@@ -33,19 +33,19 @@
 til.Hash
-Map
+Set
 ;%0A%0Apubli
@@ -233,39 +233,28 @@
         Hash
-Map%3CCharacter, 
+Set%3C
 Character%3E h
@@ -269,23 +269,12 @@
 Hash
-Map%3CCharacter, 
+Set%3C
 Char
@@ -288,35 +288,8 @@
 );%0A%0A
-        char c = 0, d = 0;%0A
     
@@ -332,16 +332,21 @@
         
+char 
 c = s.ch
@@ -386,17 +386,12 @@
 ains
-Key
 (c))
- %7B
  // 
@@ -443,15 +443,12 @@
  hs.
-put(c, 
+add(
 c);%0A
@@ -458,18 +458,16 @@
         
- %7D
  else %7B 
@@ -501,56 +501,34 @@
     
-if (r - l %3E max)%0A                    max = r - l
+max = Math.max(r - l, max)
 ;%0A  
@@ -552,13 +552,8 @@
 le (
-(d = 
 s.ch
@@ -563,17 +563,14 @@
 t(l)
-)
  != c)
- %7B
  // 
@@ -625,54 +625,23 @@
 ove(
-d);%0A                    l++;%0A                %7D
+s.charAt(l++));
 %0A   
@@ -728,69 +728,35 @@
     
-if (r - l %3E max)%0A            max = r - l;%0A%0A        return
+return Math.max(r - l,
  max
+)
 ;%0A  

Update Longest Substring Without Repeating