题解 | #滑动窗口的最大值#简单好理解
滑动窗口的最大值
https://www.nowcoder.com/practice/1624bc35a45c42c0bc17d17fa0cba788
class Solution: def maxInWindows(self , num: List[int], size: int) -> List[int]: res = [] #窗口大于数组长度的时候,返回空 if size <= len(num) and size != 0: #数组后面要空出窗口大小,避免越界 for l in range (len(num) - size + 1): r = l + size - 1 if l == 0: maxn = max(num[l : r+1]) res.append(maxn) else: if num[l-1] < maxn and num[r] < maxn: res.append(maxn) continue elif num[l-1] == maxn: maxn = max(num[l:r+1]) res.append(maxn) elif num[r] >= maxn: maxn = num[r] res.append(maxn) return res