mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-12 19:01:47 +08:00
批量更新数据
This commit is contained in:
@@ -1,53 +1,62 @@
|
||||
<p>You are given a <strong>0-indexed</strong> <strong>sorted</strong> array of integers <code>nums</code>.</p>
|
||||
<p>Given an integer array <code>num</code> sorted in non-decreasing order.</p>
|
||||
|
||||
<p>You can perform the following operation any number of times:</p>
|
||||
|
||||
<ul>
|
||||
<li>Choose <strong>two</strong> indices, <code>i</code> and <code>j</code>, where <code>i < j</code>, such that <code>nums[i] < nums[j]</code>.</li>
|
||||
<li>Choose <strong>two</strong> indices, <code>i</code> and <code>j</code>, where <code>nums[i] < nums[j]</code>.</li>
|
||||
<li>Then, remove the elements at indices <code>i</code> and <code>j</code> from <code>nums</code>. The remaining elements retain their original order, and the array is re-indexed.</li>
|
||||
</ul>
|
||||
|
||||
<p>Return <em>an integer that denotes the <strong>minimum</strong> length of </em><code>nums</code><em> after performing the operation any number of times (<strong>including zero</strong>).</em></p>
|
||||
|
||||
<p>Note that <code>nums</code> is sorted in <strong>non-decreasing</strong> order.</p>
|
||||
<p>Return the <strong>minimum</strong> length of <code>nums</code> after applying the operation zero or more times.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,3,4,9]
|
||||
<strong>Output:</strong> 0
|
||||
<strong>Explanation:</strong> Initially, nums = [1, 3, 4, 9].
|
||||
In the first operation, we can choose index 0 and 1 because nums[0] < nums[1] <=> 1 < 3.
|
||||
Remove indices 0 and 1, and nums becomes [4, 9].
|
||||
For the next operation, we can choose index 0 and 1 because nums[0] < nums[1] <=> 4 < 9.
|
||||
Remove indices 0 and 1, and nums becomes an empty array [].
|
||||
Hence, the minimum length achievable is 0.</pre>
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">nums = [1,2,3,4]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">0</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p><img src="https://assets.leetcode.com/uploads/2024/05/18/tcase1.gif" style="width: 160px; height: 70px;" /></p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [2,3,6,9]
|
||||
<strong>Output:</strong> 0
|
||||
<strong>Explanation:</strong> Initially, nums = [2, 3, 6, 9].
|
||||
In the first operation, we can choose index 0 and 2 because nums[0] < nums[2] <=> 2 < 6.
|
||||
Remove indices 0 and 2, and nums becomes [3, 9].
|
||||
For the next operation, we can choose index 0 and 1 because nums[0] < nums[1] <=> 3 < 9.
|
||||
Remove indices 0 and 1, and nums becomes an empty array [].
|
||||
Hence, the minimum length achievable is 0.
|
||||
</pre>
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">nums = [1,1,2,2,3,3]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">0</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p><img src="https://assets.leetcode.com/uploads/2024/05/19/tcase2.gif" style="width: 240px; height: 70px;" /></p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,1,2]
|
||||
<strong>Output:</strong> 1
|
||||
<strong>Explanation:</strong> Initially, nums = [1, 1, 2].
|
||||
In an operation, we can choose index 0 and 2 because nums[0] < nums[2] <=> 1 < 2.
|
||||
Remove indices 0 and 2, and nums becomes [1].
|
||||
It is no longer possible to perform an operation on the array.
|
||||
Hence, the minimum achievable length is 1.
|
||||
</pre>
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">nums = [1000000000,1000000000]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">2</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>Since both numbers are equal, they cannot be removed.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 4:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">nums = [2,3,4,4,4]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">1</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p><img src="https://assets.leetcode.com/uploads/2024/05/19/tcase3.gif" style="width: 210px; height: 70px;" /></p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
Reference in New Issue
Block a user