题解 | #滑动窗口的最大值#
滑动窗口的最大值
http://www.nowcoder.com/practice/1624bc35a45c42c0bc17d17fa0cba788
def maxInWindows(self , num: List[int], size: int) -> List[int]:
# write code here
l=len(num)
res =[max(num[0:size])]
for i in range(size,l):
if num[i-size]<res[-1]:
if num[i]<res[-1]:
res.append(res[-1])
else:
res.append(num[i])
else:
res.append(max(num[i-size+1:i+1]))
return res