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

滑动窗口的最大值

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

相关推荐

Aki-Tomoya:窝趣,人家这是先富带动后富,共同富裕了属于是
投递英伟达等公司8个岗位
点赞 评论 收藏
分享
02-11 17:51
腾讯_TEG_技术
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务