publicclassSolution { publicint[] maxSlidingWindow(int[] nums, int k) { if (nums == null || nums.length == 0) return nums; int[] result = newint[nums.length - k + 1]; LinkedList<Integer> queue = new LinkedList<Integer>(); for (int i = 0; i < nums.length; i++) { while (!queue.isEmpty() && nums[queue.peekLast()] < nums[i]) queue.pollLast(); queue.add(i); if (queue.peekFirst() == i - k) queue.pollFirst(); if (i >= k - 1) result[i - k + 1] = nums[queue.peekFirst()]; } return result; } }