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

滑动窗口的最大值

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
全部评论

相关推荐

大家收到面试预通知了吗?
投递中国邮政储蓄银行等公司8个岗位 >
点赞 评论 收藏
转发
点赞 评论 收藏
转发
点赞 收藏 评论
分享
牛客网
牛客企业服务