/** * @param {number[]} nums * @param {number} k * @return {number[]} */ var maxSlidingWindow = function (nums, k) { let len = nums.length; let res = []; if (k >= len) return [Math.max.apply(null, nums)]; for (let i = 0; i <= len - k; i++) { res.push(Math.max.apply(null, nums.slice(i, i + k))); } return res; };
let len = nums.length; let queue = newQueue(); let res = []; if(k === 0) return []; for(let i = 0; i < k - 1; i ++) { queue.push(nums[i]); } for(let i = k - 1; i < len; i ++) { queue.push(nums[i]); res.push(queue.max()); queue.pop(nums[i - k + 1]); } return res; };