class Solution {
public int lengthOfLongestSubstring(String s) {
Set<Character> set=new HashSet();
int right=-1;
int maxlength=0;
for(int i=0;i<s.length();i++){
if(i!=0){
set.remove(s.charAt(i-1));
}
while (right+1<s.length()&&!set.contains(s.charAt(right+1))){
set.add(s.charAt(right+1));
right++;
}
maxlength=Math.max(maxlength,right-i+1);
}
return maxlength;
}
}
https://blog.csdn.net/nanhuaibeian/article/details/109378129