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)/删除最短的子数组使剩余数组有序 [shortest-subarray-to-be-removed-to-make-array-sorted].html
2022-03-29 12:43:11 +08:00

48 lines
1.4 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>arr</code>&nbsp;,请你删除一个子数组(可以为空),使得 <code>arr</code>&nbsp;中剩下的元素是 <strong>非递减</strong> 的。</p>
<p>一个子数组指的是原数组中连续的一个子序列。</p>
<p>请你返回满足题目要求的最短子数组的长度。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>arr = [1,2,3,10,4,2,3,5]
<strong>输出:</strong>3
<strong>解释:</strong>我们需要删除的最短子数组是 [10,4,2] ,长度为 3 。剩余元素形成非递减数组 [1,2,3,3,5] 。
另一个正确的解为删除子数组 [3,10,4] 。</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>arr = [5,4,3,2,1]
<strong>输出:</strong>4
<strong>解释:</strong>由于数组是严格递减的,我们只能保留一个元素。所以我们需要删除长度为 4 的子数组,要么删除 [5,4,3,2],要么删除 [4,3,2,1]。
</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>arr = [1,2,3]
<strong>输出:</strong>0
<strong>解释:</strong>数组已经是非递减的了,我们不需要删除任何元素。
</pre>
<p><strong>示例 4</strong></p>
<pre>
<strong>输入:</strong>arr = [1]
<strong>输出:</strong>0
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= arr.length &lt;= 10^5</code></li>
<li><code>0 &lt;= arr[i] &lt;= 10^9</code></li>
</ul>