SOURCE

function maxSlideWindow(nums, k) {
    const n = nums.length;
    const deque = [];
    const res = [];

    for (let i = 0;i < n;i++) {
        while(deque.length && nums[deque[deque.length - 1]] < nums[i]) {
            deque.pop();
        }
        while(deque.length && deque[0] <= i - k) {
            deque.shift();
        }
        deque.push(i);
        if (i >= k - 1) {
            res.push(queue[0]);
        } 
    }
    return res;
}
console 命令行工具 X clear

                    
>
console