哈希set保存窗口中字符的情况
class Solution {
public int lengthOfLongestSubstring(String s) {
int len = s.length();
int left = 0;
int right = 0;
Set<Character> set = new HashSet<>();
int max = 0;
for(right = 0; right < len;right++){
while(set.contains(s.charAt(right))){
set.remove(s.charAt(left));
left+= 1;
}
set.add(s.charAt(right));;
max = Math.max(max,set.size());
}
return max;
}
}