题解 | #滑动窗口的最大值#
滑动窗口的最大值
https://www.nowcoder.com/practice/1624bc35a45c42c0bc17d17fa0cba788
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param num int整型一维数组 # @param size int整型 # @return int整型一维数组 # class Solution: def maxInWindows(self , num: List[int], size: int) -> List[int]: # write code here、 n = len(num) s= [] if size > n or n == 0 or size == 0: return [] if size == 1 : return num left , right = 0,size-1 while right <n: nleft = left nright = right themax = -1000 while nleft<nright: if num[nleft] > num[nright]: nright-=1 themax = num[nleft] else: nleft+=1 themax = num[nright] s.append(themax) left+=1 right+=1 return s