3. 无重复字符的最长子串
class Solution {
public int lengthOfLongestSubstring(String s) {
Set<Character> set = new HashSet<>();
int left = 0;
int right = 0;
int res = 0;
while (right < s.length()) {
if (!set.add(s.charAt(right))) {
while (s.charAt(left) != s.charAt(right)) {
set.remove(s.charAt(left));
left++;
}
left++;
}
res = Math.max(res, right - left + 1);
right++;
}
return res;
}
}