Sliding Window
Template
int j = 0
for i in range(n):
while j<n && array 不滿足條件
j+=1
拓寬條件
if array 滿足條件
看是不是最優的
num[i]移出array3. Longest Substring Without Repeating Characters
def lengthOfLongestSubstring(self, s: str) -> int:
record = set()
res = 0
i, j = 0, 0
while j < len(s):
while j < len(s) and s[j] not in record:
record.add(s[j])
j+=1
res = max(res, j-i)
record.remove(s[i])
i+=1
return res340 Longest Substring with At Most K Distinct Characters
76. Minimum Window Substring
209. Minimum Size Subarray Sum
862. Shortest Subarray with Sum at Least K
395. Longest Substring with At Least K Repeating Characters
Last updated