题目描述
blablabla
样例
from collections import deque
class Solution(object):
def maxInWindows(self, nums, k):
"""
:type nums: List[int]
:type k: int
:rtype: List[int]
"""
if not nums:
return []
res = []
q = deque([])
for i in range(len(nums)):
print(q)
if len(q) != 0 and i - q[0] >= k: # 判断队头是否需要出队
q.popleft()
while len(q) != 0 and nums[q[-1]] < nums[i]: # 维护队列单调性
q.pop() # 如果nums[i]大于或等于队尾元素下标所对应的值,则当前队尾再也不可能充当某个滑动窗口的最大值了,故需要队尾出队
q.append(i)
if i >= k - 1:
res.append(nums[q[0]]) # 取队头作为窗口最大元素
return res