package leetcode;

import java.util.HashMap;
import java.util.Map;

/**
 * https://leetcode.com/problems/longest-substring-without-repeating-characters/
 */
public class Problem3 {
    public int lengthOfLongestSubstring(String s) {
        Map<Character, Integer> charToIndices = new HashMap<>();
        int maxLength = 0, minIdx = 0;
        for (int i = 0; i < s.length(); i++) {
            if (charToIndices.containsKey(s.charAt(i))) {
                minIdx = Math.max(charToIndices.get(s.charAt(i)) + 1, minIdx);
            }
            maxLength = Math.max(maxLength, i - minIdx + 1);
            charToIndices.put(s.charAt(i), i);
        }
        return maxLength;
    }
}

@@ -258,29 +258,19 @@
 nteger%3E 
-charToIndices
+map
  = new H
@@ -297,27 +297,33 @@
 int 
-maxLength = 0, minI
+answer = 0;%0A        int i
 dx =
@@ -389,25 +389,49 @@
     
-if (charToIndices
+char c = s.charAt(i);%0A            if (map
 .con
@@ -439,27 +439,17 @@
 ainsKey(
-s.charAt(i)
+c
 )) %7B%0A   
@@ -461,20 +461,17 @@
         
-minI
+i
 dx = Mat
@@ -480,48 +480,25 @@
 max(
-charToIndices.get(s.charAt(i)
+map.get(c
 ) + 1, 
-minI
+i
 dx);
@@ -524,25 +524,22 @@
         
-maxLength
+answer
  = Math.
@@ -546,27 +546,21 @@
 max(
-maxLength
+answer
 , i - 
-minI
+i
 dx +
@@ -580,37 +580,17 @@
     
-charToIndices.put(s.charAt(i)
+map.put(c
 , i)
@@ -620,17 +620,14 @@
 urn 
-maxLength
+answer
 ;%0A  

Update problem 3