滑动窗口
class Solution {
public int lengthOfLongestSubstring(String s) {
HashSet<Character> set = new HashSet<>();
int res = 0;
for(int l = 0, r = 0; r < s.length(); r++){
char c = s.charAt(r);
while(set.contains(c)){
char d = s.charAt(l++);
set.remove(d);
}
set.add(c);
res = Math.max(res, r - l + 1);
}
return res;
}
}