class Solution {
public int lengthOfLongestSubstring(String s) {
int l = 0, r = -1;
int max = 0;
Set<Character> set = new HashSet<>();
while(r + 1< s.length()){
while(r + 1 < s.length() && !set.contains(s.charAt(r + 1))){
set.add(s.charAt(r + 1));
r++;
}
max = Math.max(r - l + 1, max);
set.remove(s.charAt(l));
l++;
}
return max;
}
}
09-18
889
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
09-04
787
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
07-23
9230
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
03-16
331
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
04-28