class Solution {
public int lengthOfLongestSubstring(String s) {
int len = s.length();
Set<Character> set = new HashSet<>();
int left = 0;
int right = 0;
int max = 0;
for(; left < len; left++){
if(left != 0){
set.remove(s.charAt(left - 1));
}
while(right < len){
if(set.contains(s.charAt(right))){
break;
}else{
set.add(s.charAt(right));
}
right++;
}
max = Math.max(max, right - left);
}
return max;
}
}
剑指-016
最新推荐文章于 2024-07-24 14:54:00 发布