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)/长度为 K 的子数组的能量值 I [find-the-power-of-k-size-subarrays-i].html
2024-08-27 23:06:51 +08:00

61 lines
2.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>n</code>&nbsp;的整数数组&nbsp;<code>nums</code>&nbsp;和一个正整数&nbsp;<code>k</code>&nbsp;</p>
<p>一个数组的 <strong>能量值</strong> 定义为:</p>
<ul>
<li>如果 <strong>所有</strong>&nbsp;元素都是依次&nbsp;<strong>连续</strong><strong>上升</strong> 的,那么能量值为 <strong>最大</strong>&nbsp;的元素。</li>
<li>否则为 -1 。</li>
</ul>
<p>你需要求出 <code>nums</code>&nbsp;中所有长度为 <code>k</code>&nbsp;&nbsp;<span data-keyword="subarray-nonempty">子数组</span>&nbsp;的能量值。</p>
<p>请你返回一个长度为 <code>n - k + 1</code>&nbsp;的整数数组&nbsp;<code>results</code>&nbsp;,其中&nbsp;<code>results[i]</code>&nbsp;是子数组&nbsp;<code>nums[i..(i + k - 1)]</code>&nbsp;的能量值。</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>nums = [1,2,3,4,3,2,5], k = 3</span></p>
<p><b>输出:</b>[3,4,-1,-1,-1]</p>
<p><strong>解释:</strong></p>
<p><code>nums</code>&nbsp;中总共有 5 个长度为 3 的子数组:</p>
<ul>
<li><code>[1, 2, 3]</code>&nbsp;中最大元素为 3 。</li>
<li><code>[2, 3, 4]</code>&nbsp;中最大元素为 4 。</li>
<li><code>[3, 4, 3]</code>&nbsp;中元素 <strong>不是</strong>&nbsp;连续的。</li>
<li><code>[4, 3, 2]</code>&nbsp;中元素 <b>不是</b>&nbsp;上升的。</li>
<li><code>[3, 2, 5]</code>&nbsp;中元素 <strong>不是</strong>&nbsp;连续的。</li>
</ul>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>nums = [2,2,2,2,2], k = 4</span></p>
<p><span class="example-io"><b>输出:</b>[-1,-1]</span></p>
</div>
<p><strong class="example">示例 3</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>nums = [3,2,3,2,3,2], k = 2</span></p>
<p><span class="example-io"><b>输出:</b>[-1,3,-1,3,-1]</span></p>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= n == nums.length &lt;= 500</code></li>
<li><code>1 &lt;= nums[i] &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= k &lt;= n</code></li>
</ul>