classSolution{ publicintlengthOfLongestSubstring(String s){ Map<Character, Integer> need = new HashMap<>();
int left = 0, right = 0, start = 0, len = 0; while (right < s.length()) { char c = s.charAt(right); right++; need.merge(c, 1, (oldVal, newVal) -> ++oldVal); while (need.get(c).equals(2)) { if (right - 1 - left > len) { start = left; len = right - 1 - left; } char l = s.charAt(left); left++; need.compute(l, (k, v) -> --v); } } return right - left > len ? right - left : len; } }