mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 03:34:02 +08:00
Update 0239.滑动窗口最大值.md
This commit is contained in:
@ -273,8 +273,8 @@ class Solution {
|
|||||||
int[] res = new int[n - k + 1];
|
int[] res = new int[n - k + 1];
|
||||||
int idx = 0;
|
int idx = 0;
|
||||||
for(int i = 0; i < n; i++) {
|
for(int i = 0; i < n; i++) {
|
||||||
// 根据题意,i为nums下标,是要在[i - k + 1, k] 中选到最大值,只需要保证两点
|
// 根据题意,i为nums下标,是要在[i - k + 1, i] 中选到最大值,只需要保证两点
|
||||||
// 1.队列头结点需要在[i - k + 1, k]范围内,不符合则要弹出
|
// 1.队列头结点需要在[i - k + 1, i]范围内,不符合则要弹出
|
||||||
while(!deque.isEmpty() && deque.peek() < i - k + 1){
|
while(!deque.isEmpty() && deque.peek() < i - k + 1){
|
||||||
deque.poll();
|
deque.poll();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user