题目:无重复字符的最长子串 点击跳转
文章目录
题目描述

滑动窗口
java
class Solution {
public int lengthOfLongestSubstring(String s) {
HashSet<Character> set = new HashSet<>();
int left = 0;
int right = 0;
int res = 0;
for(;right<s.length();right++){
while(set.contains(s.charAt(right))){
set.remove(s.charAt(left));
left++;
}
set.add(s.charAt(right));
res = Math.max(res,right - left + 1);
}
return res;
}
}