# 239-滑动窗口最大值问题-难
https://leetcode-cn.com/problems/sliding-window-maximum/ (opens new window)
# 我的解答
# 官方解答
# 优质解答
[图解字节&leetcode151:翻转字符串里的单词 · Issue #18 · sisterAn/JavaScript-Algorithms (github.com) (opens new window)](https://github.com/sisterAn/JavaScript-Algorithms/issues/18)
-
var maxSlidingWindow = function (nums, k) { const deque = [] const result = [] for (let i = 0; i < nums.length; i++) { // 把滑动窗口之外的踢出 if (i - deque[0] >= k) { deque.shift() } while (nums[deque[deque.length - 1]] <= nums[i]) { deque.pop() } deque.push(i) if (i >= k - 1) { result.push(nums[deque[0]]) } } return result }