class Solution {
public int lengthOfLongestSubstring(String s) {
char[] chars = s.toCharArray();
int max = 0;
Map<Character, Integer> map = new HashMap<>();
int i = 0;
for (int j = 0; j < chars.length; j++) {
if (map.containsKey(chars[j])) {
Integer del = map.get(chars[j]);
i = Integer.max(i, del + 1);
}
int len = j - i + 1;
max = Integer.max(max, len);
map.put(chars[j], j);
}
return max;
}
}