Skip to content

Commit a86cd87

Browse files
committed
update cheatsheet
1 parent f8e1500 commit a86cd87

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

doc/cheatsheet/sliding_window.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,18 @@ for r in range(len(r)):
8686
//-------------------------
8787
// V1 : while - while
8888
//-------------------------
89+
// sliding window pattern
90+
// https://labuladong.online/algo/essential-technique/array-two-pointers-summary/#%E5%8E%9F%E5%9C%B0%E4%BF%AE%E6%94%B9
8991
int left = 0, right = 0;
90-
while (right < s.size()) {
91-
window.add(s[right]);
92+
93+
while (right < nums.size()) {
94+
// enlarge window
95+
window.addLast(nums[right]);
9296
right++;
93-
// NOTE : most of the sliding windonw trick
94-
// is dealing with "valid" conditions
95-
// and how to cache some conditions for verfication
96-
while (valid) {
97-
window.remove(s[left]);
97+
98+
while (window needs shrink) {
99+
// lower window
100+
window.removeFirst(nums[left]);
98101
left++;
99102
}
100103
}

0 commit comments

Comments
 (0)