题解 | #BM45 滑动窗口的最大值#
滑动窗口的最大值
https://www.nowcoder.com/practice/1624bc35a45c42c0bc17d17fa0cba788
class Solution: def maxInWindows(self, num: List[int], size: int) -> List[int]: # 0~size-1 [0,size] # n-size~n-1 [n-size,n] curr_max = max(num[:size]) allWindowMax = [curr_max] for i in range(1, len(num)-size+1): if num[i-1] == curr_max: curr_max = max(num[i:i+size]) # 很耗时 else: curr_max = max(curr_max, num[i+size-1]) allWindowMax.append(curr_max) return allWindowMax
这个解法在 leetcode 那边直接超时,有待优化