题解 | #滑动窗口的最大值#
滑动窗口的最大值
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
rst = list()
n = len(num) - size
if size < 1:
return rst
for i in range(n + 1):
print("====> num[{0}]: {1}, window: {2}, max: {3}".format(i, num[i], num[i:i+size], max(num[i:i+size])))
rst.append(max(num[i:i+size]))
return rst
自己的思路,记录一下。之前使用过矩阵计算图像的邻域,因此清楚如何生成窗口矩阵,因此,写的快一些。

查看5道真题和解析