classSolution{ publicintlengthOfLongestSubstring(String s){ char[] c = s.toCharArray(); int n = c.length; int l = 0, r = 0, max = 0; Set<Character> hashSet = new HashSet<>(); while (r < n) { while (hashSet.contains(c[r])) { hashSet.remove(c[l++]); } hashSet.add(c[r++]); max = Math.max(max, r - l); } return max; }