public class Solution {
    public ArrayList<Integer> maxInWindows(int [] num, int size) {
        int len = num.length;
        ArrayList<Integer> res = new ArrayList<>();
        if (num == null || len == 0 || size ==0|| len<size){
            return  res;
        }
//       存储的数组的下标
        Deque<Integer>  deque = new ArrayDeque<>();
        
        for (int i = 0; i < size; i++) {
            int item  = num[i];
            while (!deque.isEmpty()&&num[deque.peek()]<=item){
                deque.pollLast();
            }
            deque.offerLast(i);
        }
        int  WindowLen = len-size+1;
        for (int i = 0; i < len-size+1; i++) {
              int left =  i;
              int right = left+size-1;
            int right_num = num[right];
            while (!deque.isEmpty()&&num[deque.peekLast()]<=right_num){
                deque.pollLast();
            }
            deque.offerLast(right);

            while(left>deque.peek()){
                deque.pollFirst();
            }
            res.add(num[deque.peek()]);
        }
       return  res;
    }
}