标签:code png repeat out end 分享 nta contain tin
public class Solution {
public int lengthOfLongestSubstring(String s) {
int n = s.length();
Set<Character> set = new HashSet<>();
int ans = 0, i = 0, j = 0;
while (i < n && j < n) {
// try to extend the range [i, j]
if (!set.contains(s.charAt(j))){
set.add(s.charAt(j++));
ans = Math.max(ans, j - i);
}
else {
set.remove(s.charAt(i++));
}
}
return ans;
}
}
Leetcode(Longest Substring Without Repeating Characters)
标签:code png repeat out end 分享 nta contain tin
原文地址:https://www.cnblogs.com/hugeng007/p/9892836.html