题目描述
blablabla
class Solution {
public int[] maxInWindows(int[] nums, int k) {
int[] res=new int[nums.length-k+1];
Deque<Integer> queue=new ArrayDeque<>();
for (int i = 0; i <nums.length; i++) {
if (!queue.isEmpty()&&i-queue.peekLast()==k){
queue.pollLast();
}
//从对首开始比较大小
while (!queue.isEmpty()&&nums[queue.peek()]<nums[i])
queue.poll();
//存入index;
queue.push(i);
if (i>=k-1)
res[i-k+1]=nums[queue.peekLast()];
}
return res;
}
}