Class Solution
java.lang.Object
g0201_0300.s0239_sliding_window_maximum.Solution
239 - Sliding Window Maximum.<p>Hard</p>
<p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the max sliding window</em>.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> nums = [1,3,-1,-3,5,3,6,7], k = 3</p>
<p><strong>Output:</strong> [3,3,5,5,6,7]</p>
<p><strong>Explanation:</strong></p>
<pre><code> 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
</code></pre>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> nums = [1], k = 1</p>
<p><strong>Output:</strong> [1]</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> nums = [1,-1], k = 1</p>
<p><strong>Output:</strong> [1,-1]</p>
<p><strong>Example 4:</strong></p>
<p><strong>Input:</strong> nums = [9,11], k = 2</p>
<p><strong>Output:</strong> [11]</p>
<p><strong>Example 5:</strong></p>
<p><strong>Input:</strong> nums = [4,-2], k = 2</p>
<p><strong>Output:</strong> [4]</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
<li><code>-10<sup>4</sup> <= nums[i] <= 10<sup>4</sup></code></li>
<li><code>1 <= k <= nums.length</code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
maxSlidingWindow
public int[] maxSlidingWindow(int[] nums, int k)
-