题解 | #滑动窗口的最大值#
滑动窗口的最大值
https://www.nowcoder.com/practice/1624bc35a45c42c0bc17d17fa0cba788
import java.util.*;
public class Solution {
public ArrayList<Integer> maxInWindows(int [] num, int size) {
ArrayList<Integer> list = new ArrayList<Integer>();
if (size > num.length) {
return list;
}
if(size==1){
for(int i=0;i<num.length;i++){
list.add(num[i]);
}
return list;
}
int pos = 0;
int max = num[pos];
int count = 0;
for (int i = 0; i < num.length;) {
count++;
if (count == size ) {
list.add(max);
pos++;
i = pos;
max = num[pos];
count=0;
continue;
}
if (i + 1 < num.length && max < num[i + 1]) {
max = num[i + 1];
}
i++;
}
return list;
}
}
