美文网首页
【LintCode 题解 | Google 面试高频题:滑动窗口

【LintCode 题解 | Google 面试高频题:滑动窗口

作者: SunnyZhao2019 | 来源:发表于2020-02-04 17:54 被阅读0次

【题目描述】
给出一个可能包含重复的整数数组,和一个大小为 k 的滑动窗口, 从左到右在数组中滑动这个窗口,找到数组中每个窗口内的最大值。

【考点分析】
样例
样例 1:

输入:
[1,2,7,7,8]
3
输出:
[7,7,8]

解释:
最开始,窗口的状态如下:[|1, 2 ,7| ,7 , 8], 最大值为 7;
然后窗口向右移动一位:[1, |2, 7, 7|, 8], 最大值为 7;
最后窗口再向右移动一位:[1, 2, |7, 7, 8|], 最大值为 8.
样例 2:

输入:
[1,2,3,1,2,3]
5
输出:
[3,3]

解释:
最开始,窗口的状态如下: [|1,2,3,1,2 | ,3] , 最大值为3;
然后窗口向右移动一位.[1, |2,3,1,2,3], 最大值为 3;

【九章参考程序】

https://www.jiuzhang.com/solution/sliding-window-maximum/?utm_source=sc-jianshu-fks

微信图片_20200204175131.png

相关文章

网友评论

      本文标题:【LintCode 题解 | Google 面试高频题:滑动窗口

      本文链接:https://www.haomeiwen.com/subject/zxqdxhtx.html