无重复字符的最长子串
class Solution {
public int lengthOfLongestSubstring(String s) {
int n = s.length();
Set<Character> sets = new HashSet<>();
int i =0, j =0;
int result = 0;
while(i < n && j < n){
if(!sets.contains(s.charAt(j))){
sets.add(s.charAt(j++));
result = Math.max(result,j-i);
}else{
sets.remove(s.charAt(i++));
}
}
return result;
}
}