We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent d9b317f commit 6c66eb1Copy full SHA for 6c66eb1
src/main/java/com/algorithm/shoppe/hard/MaxSlidingWindow.java
@@ -42,18 +42,19 @@ public void pop(int n) {
42
43
public static int[] maxSlidingWindow(int[] nums, int k) {
44
MonotonicQueue window = new MonotonicQueue();
45
+
46
47
List<Integer> res = new ArrayList<>();
- for (int i =0; i< nums.length; i++) {
- if (i<k-1) {
48
+ for (int i = 0; i < nums.length; i++) {
49
+ if (i < k - 1) {
50
window.push(nums[i]);
- }else {
51
+ } else {
52
53
res.add(window.max());
- window.pop(nums[i-k+1]);
54
+ window.pop(nums[i - k + 1]);
55
}
56
-
- int[] arr = new int[res.size()];
57
+ int[] arr = new int[res.size() - 1];
58
for (int i = 0; i < res.size(); i++) {
59
arr[i] = res.get(i);
60
0 commit comments