Sliding Window Maximum
hard 原题链接:https://leetcode.com/problems/sliding-window-maximum/
Sliding window maximum
描述
You are given an array of integers
nums, there is a sliding window of sizekwhich is moving from the very left of the array to the very right. You can only see theknumbers in the window. Each time the sliding window moves right by one position.Return the max sliding window.
例子
Input: nums = [1,3,-1,-3,5,3,6,7], k = 3
Output: [3,3,5,5,6,7]
Explanation:
Window position Max
[1 3 -1] -3 5 3 6 7 3
1 [3 -1 -3] 5 3 6 7 3
1 3 [-1 -3 5] 3 6 7 5
1 3 -1 [-3 5 3] 6 7 5
1 3 -1 -3 [5 3 6] 7 6
1 3 -1 -3 5 [3 6 7] 7
解法一 Time Limit Exceeded O(kN)
解法二 use dequeue O(N)
better one
最后更新于
这有帮助吗?