https://leetcode.cn/problems/sliding-window-maximum/
class Solution {
public int[] maxSlidingWindow(int[] nums, int k) {
if(nums==null||nums.length==0||k<0){
return null;
}
int[] result= new int [nums.length-k+1];
LinkedList<Integer> queue = new LinkedList<Integer>();
int index = 0;
for(int i = 0 ; i < nums.length;i++){
while (!queue.isEmpty()&&nums[queue.peekLast()]<=nums[i]){
queue.pollLast();
}
queue.addLast(i);
if(i-k==queue.peekFirst()){
queue.pollFirst();
}
if(i>=k-1){
result[index++] = nums[queue.peekFirst()];
}
}
return result;
}
}
标签:index,nums,int,最大值,queue,++,算法,result,数组 From: https://www.cnblogs.com/chenyangwang/p/17538864.html