题解 | #滑动窗口的最大值#
滑动窗口的最大值
http://www.nowcoder.com/practice/1624bc35a45c42c0bc17d17fa0cba788
记录一下,很有意思
# -*- coding:utf-8 -*- class Solution: def maxInWindows(self, num, size): # write code here if not num or not size:return None //前提条件 lenth = len(num) - size + 1 //这里正好是窗口的大小 res =[] for i in range(lenth): //range很重要 max1 = max(num[i:size+i]) //移动的点 res.append(max1) return res