1
class Solution {
2
public int[] maxSlidingWindow(int[] nums, int k) {
3
Deque<Integer> queue = new LinkedList<>();
4
int l = 0, r = 0;
5
int[] res = new int[nums.length - k + 1];
6
int index = 0;
7
while (r < nums.length) {
8
int n = nums[r++];
9
while (!queue.isEmpty() && n > queue.peekLast()) {
10
queue.pollLast();
11
}
12
queue.offer(n);
13
while (r - l > k) {
14
int m = nums[l++];
15
if (m == queue.peekFirst()) {
16
queue.pollFirst();
17
}
18
}
19
if (r - l == k) {
20
res[index++] = queue.peekFirst();
21
}
22
}
23
return res;
24
}
25
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0