题解 | #滑动窗口的最大值#
滑动窗口的最大值
http://www.nowcoder.com/practice/1624bc35a45c42c0bc17d17fa0cba788
-- coding:utf-8 --
class Solution:
def maxInWindows(self, num, size):
# write code here
if size ==1:return num
if size == 0 :return []
if size > len(num):return []
from collections import deque
from collections import deque
win = deque()
res = []
for i in range(len(num)):
if i>=size and win[0] == num[i-size]: win.popleft()
while win and win[-1] < num[i]:win.pop()
win.append(num[i])
if i>=size-1: res.append(win[0])
return res
return res

