1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/滑动窗口最大值 [sliding-window-maximum].html
2022-03-29 12:43:11 +08:00

39 lines
1.2 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>给你一个整数数组 <code>nums</code>,有一个大小为&nbsp;<code>k</code><em>&nbsp;</em>的滑动窗口从数组的最左侧移动到数组的最右侧。你只可以看到在滑动窗口内的 <code>k</code>&nbsp;个数字。滑动窗口每次只向右移动一位。</p>
<p>返回 <em>滑动窗口中的最大值 </em></p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<b>输入:</b>nums = [1,3,-1,-3,5,3,6,7], k = 3
<b>输出:</b>[3,3,5,5,6,7]
<b>解释:</b>
滑动窗口的位置 最大值
--------------- -----
[1 3 -1] -3 5 3 6 7 <strong>3</strong>
1 [3 -1 -3] 5 3 6 7 <strong>3</strong>
1 3 [-1 -3 5] 3 6 7 <strong> 5</strong>
1 3 -1 [-3 5 3] 6 7 <strong>5</strong>
1 3 -1 -3 [5 3 6] 7 <strong>6</strong>
1 3 -1 -3 5 [3 6 7] <strong>7</strong>
</pre>
<p><strong>示例 2</strong></p>
<pre>
<b>输入:</b>nums = [1], k = 1
<b>输出:</b>[1]
</pre>
<p>&nbsp;</p>
<p><b>提示:</b></p>
<ul>
<li><code>1 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
<li><code>-10<sup>4</sup>&nbsp;&lt;= nums[i] &lt;= 10<sup>4</sup></code></li>
<li><code>1 &lt;= k &lt;= nums.length</code></li>
</ul>