滑动窗口最大值数组_python3

生成窗口最大值数组

http://www.nowcoder.com/questionTerminal/b316c7f9617744b98fa311ae29ac516c

单调队列

def solve(l, n, k):
    index = []
    for i in range(n):
        while index and l[index[-1]] < l[i]:
            index.pop(-1)
        index.append(i)
        while index and i - index[0] >= k:
            index.pop(0)
        print(index)
        if i >= k - 1:
            if i != n - 1:
                print(l[index[0]], end = ' ')
            else:
                print(l[index[0]])

while True:
    try:
        n, k = map(int, input().split())
        l = list(map(int, input().split()))
        solve(l, n, k)
    except EOFError:
        break
全部评论

相关推荐

09-22 22:22
中山大学 Java
双尔:赌对了,不用经历秋招的炼狱真的太好了,羡慕了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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