Python 代码
class Solution(object):
def maxInWindows(self, nums, k):
q = []
res = []
for i,v in enumerate(nums):
while q and q[0] == i - k: #把遍历长度超过k的数从左侧去掉
q.pop(0)
while q and v > nums[q[-1]]: #把永远不可能为值的数从右侧去掉
q.pop()
q.append(i)
res.append(nums[q[0]])
return res[k - 1:]