You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: 算法思维系列/滑动窗口技巧进阶.md
+5-3
Original file line number
Diff line number
Diff line change
@@ -47,7 +47,7 @@ tags: ['滑动窗口', '核心框架', '数组']
47
47
```cpp
48
48
int left = 0, right = 0;
49
49
50
-
while (right < s.size()) {
50
+
while (left < right && right < s.size()) {
51
51
// 增大窗口
52
52
window.add(s[right]);
53
53
right++;
@@ -77,6 +77,7 @@ void slidingWindow(string s) {
77
77
while (right < s.size()) {
78
78
// c 是将移入窗口的字符
79
79
char c = s[right];
80
+
winodw.add(c)
80
81
// 增大窗口
81
82
right++;
82
83
// 进行窗口内数据的一系列更新
@@ -89,9 +90,10 @@ void slidingWindow(string s) {
89
90
/********************/
90
91
91
92
// 判断左侧窗口是否要收缩
92
-
while (window needs shrink) {
93
+
while (left < right && window needs shrink) {
93
94
// d 是将移出窗口的字符
94
95
char d = s[left];
96
+
winodw.remove(d)
95
97
// 缩小窗口
96
98
left++;
97
99
// 进行窗口内数据的一系列更新
@@ -475,13 +477,13 @@ int lengthOfLongestSubstring(string s) {
475
477
|[862. Shortest Subarray with Sum at Least K](https://leetcode.com/problems/shortest-subarray-with-sum-at-least-k/?show=1)|[862. 和至少为 K 的最短子数组](https://leetcode.cn/problems/shortest-subarray-with-sum-at-least-k/?show=1)|
0 commit comments