总体比较简单,不细说了
public int lengthOfLongestSubstring(String s) {
LinkedHashSet<Character> set = new LinkedHashSet<>();
int lastSize = 0;
int maxSize = 0;
for (int i = 0; i < s.length() ; i++) {
char temp = s.charAt(i);
set.add(temp);
if(set.size()==lastSize){
boolean start = false;
LinkedHashSet<Character> tempSet = new LinkedHashSet<>();
for (char c: set) {
if (start) {
tempSet.add(c);
continue;
}
if (c == temp) {
start = true;
}
}
set = tempSet;
set.add(temp);
}
lastSize = set.size();
if(lastSize > maxSize){
maxSize = lastSize;
}
}
return maxSize;
}