微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

[Daily Coding Problem] 18 (LeetCode 239). Sliding Window Maximum

Given an array nums,there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding window moves right by one position. Return the max sliding window.

Example:

Input: nums =,and k = 3
Output: 
Window position                Max
---------------               -----
[1  3  -1] -3  5  3  6  7       3
 1 [3  -1  -3] 5  3  6  7       3
 1  3 [-1  -3  5] 3  6  7       5
 1  3  -1 [-3  5  3] 6  7       5
 1  3  -1  -3 [5  3  6] 7       6
 1  3  -1  -3  5 [3  6  7]      7
[1,3,-1,-3,5,6,7][3,7] 
Explanation:

Note: 
You may assume k is always valid,1 ≤ k ≤ input array‘s size for non-empty array.

Follow up:
Could you solve it in linear time?

 

Same Problem with Sliding Window Maximum.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐