mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-10 01:41:41 +08:00
48 lines
1.7 KiB
HTML
48 lines
1.7 KiB
HTML
<p>给你一个整数数组 <code>nums</code>。在一次操作中,你可以选择一个子数组,并将其替换为一个等于该子数组 <strong>最大值 </strong>的单个元素。</p>
|
||
|
||
<p>返回经过零次或多次操作后,数组仍为 <strong>非递减 </strong>的情况下,数组 <strong>可能的最大长度</strong>。</p>
|
||
|
||
<p><strong>子数组 </strong>是数组中一个连续、<b>非空 </b>的元素序列。</p>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong class="example">示例 1:</strong></p>
|
||
|
||
<div class="example-block">
|
||
<p><strong>输入:</strong> <span class="example-io">nums = [4,2,5,3,5]</span></p>
|
||
|
||
<p><strong>输出:</strong> <span class="example-io">3</span></p>
|
||
|
||
<p><strong>解释:</strong></p>
|
||
|
||
<p>实现最大长度的一种方法是:</p>
|
||
|
||
<ol>
|
||
<li>将子数组 <code>nums[1..2] = [2, 5]</code> 替换为 <code>5</code> → <code>[4, 5, 3, 5]</code>。</li>
|
||
<li>将子数组 <code>nums[2..3] = [3, 5]</code> 替换为 <code>5</code> → <code>[4, 5, 5]</code>。</li>
|
||
</ol>
|
||
|
||
<p>最终数组 <code>[4, 5, 5]</code> 是非递减的,长度为 <font face="monospace">3。</font></p>
|
||
</div>
|
||
|
||
<p><strong class="example">示例 2:</strong></p>
|
||
|
||
<div class="example-block">
|
||
<p><strong>输入:</strong> <span class="example-io">nums = [1,2,3]</span></p>
|
||
|
||
<p><strong>输出:</strong> <span class="example-io">3</span></p>
|
||
|
||
<p><strong>解释:</strong></p>
|
||
|
||
<p>无需任何操作,因为数组 <code>[1,2,3]</code> 已经是非递减的。</p>
|
||
</div>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>提示:</strong></p>
|
||
|
||
<ul>
|
||
<li><code>1 <= nums.length <= 2 * 10<sup>5</sup></code></li>
|
||
<li><code>1 <= nums[i] <= 2 * 10<sup>5</sup></code></li>
|
||
</ul>
|