【数组】滑动窗口的最大值
2019-08-26 本文已影响0人
一个想当大佬的菜鸡
# -*- coding:utf-8 -*-
class Solution:
def maxInWindows(self, num, size):
# write code here
length = len(num)
if length == 0 or length < size:
return []
qu, res = [], []
for i in range(len(num)):
while qu and num[qu[-1]] < num[i]:
qu.pop()
if qu and qu[0] <= i - size:
qu.pop(0)
qu.append(i)
if size and i+1>=size:
res.append(num[qu[0]])
return res