import java.util.HashSet;
import java.util.Set;
public class LongestChildStr {
public static void main(String[] args) {
String ab="abcaeabb";
System.out.println(lengthOfLongestSubstring(ab));
Set<Character> set = new HashSet<>();
set.add('a');
set.add('b');
set.add('c');
set.forEach(ele->{
System.out.println(ele);
});
}
public static int lengthOfLongestSubstring(String s) {
//维护当前最长不重复字符子串
Set<Character> set = new HashSet<>();
int left = 0;
int right = 0;
int max = 0;
while(right<s.length()){
if(!set.contains(s.charAt(right))){
//未查到重复字符就一直加,right右移
set.add(s.charAt(right));
right++;
}else{
//right查到重复字符先不动,left右移,set删left经过的字符,直到重复的这个字符删掉为止
set.remove(s.charAt(left));
left++;
}
//每一次计算当前set子串的长度
max = Math.max(max, set.size());
}
return max;
}
}