这样写了还是会超时
public class Solution {
public int[] maxSlidingWindow(int[] nums, int k) {
if(nums.length <=1) return nums;
LinkedList<Integer> list = new LinkedList<Integer>();
PriorityQueue<Integer> maxHeap = new PriorityQueue<Integer>(10+k, Collections.reverseOrder());
int[] resultArr = new int[nums.length - k + 1];//LinkedList<Integer> result = new LinkedList<Integer>();
int i=0;
for(;i<k; i++){
list.addFirst(nums[i]);
maxHeap.offer(nums[i]);
}
while(i<nums.length){
if(list.size()!=k){
list.addFirst(nums[i]);
maxHeap.offer(nums[i]);
}else{
resultArr[i-k+1] = maxHeap.peek();
maxHeap.remove(list.size()-1);
list.remove(list.size()-1);
// int target = Integer.MIN_VALUE;
// for(int j=0; j<k; j++){
// if(list.get(j)>target){
// target = list.get(j);
// }
// }
// result.addFirst(target);
i++;
}
}
return resultArr;
}
}