题解 | #滑动窗口的最大值#

滑动窗口的最大值

http://www.nowcoder.com/practice/1624bc35a45c42c0bc17d17fa0cba788

-- coding:utf-8 --

class Solution:
    def maxInWindows(self, num, size):
        # write code here
        if size ==1:return num
        if size == 0 :return []
        if size > len(num):return []
        from collections import deque
        from collections import deque
        win = deque()
        res = []
        for i in range(len(num)):
            if i>=size and win[0] == num[i-size]: win.popleft()
            while win and win[-1] < num[i]:win.pop()
            win.append(num[i])
            if i>=size-1: res.append(win[0])
        return res 
        return res
全部评论

相关推荐

每晚夜里独自颤抖:这个在牛客不是老熟人了吗
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务