双指针法
// 滑动窗口(双指针解法)
class Solution {
public int lengthOfLongestSubstring(String s) {
int l=0,r=0;
char[] c=s.toCharArray();
HashSet<Character> set=new HashSet();
int res=0;
while(r<c.length){
if(!set.contains(c[r])){
set.add(c[r]);
r++;
}else{
set.remove(c[l]);
l++;
}
res=Math.max(res,r-l);
}
return res;
}
}