1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-25 17:50:26 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/将数组清空 [make-array-empty].html
2023-05-03 20:22:43 +08:00

131 lines
3.8 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>给你一个包含若干 <strong>互不相同</strong>&nbsp;整数的数组&nbsp;<code>nums</code>&nbsp;,你需要执行以下操作 <strong>直到</strong><strong>数组为空</strong>&nbsp;</p>
<ul>
<li>如果数组中第一个元素是当前数组中的 <strong>最小值</strong>&nbsp;,则删除它。</li>
<li>否则,将第一个元素移动到数组的 <strong>末尾</strong>&nbsp;</li>
</ul>
<p>请你返回需要多少个操作使<em>&nbsp;</em><code>nums</code><em>&nbsp;</em>为空。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<b>输入:</b>nums = [3,4,-1]
<b>输出:</b>5
</pre>
<table style="border: 2px solid black; border-collapse: collapse;">
<thead>
<tr>
<th style="border: 2px solid black; padding: 5px;">Operation</th>
<th style="border: 2px solid black; padding: 5px;">Array</th>
</tr>
</thead>
<tbody>
<tr>
<td style="border: 2px solid black; padding: 5px;">1</td>
<td style="border: 2px solid black; padding: 5px;">[4, -1, 3]</td>
</tr>
<tr>
<td style="border: 2px solid black; padding: 5px;">2</td>
<td style="border: 2px solid black; padding: 5px;">[-1, 3, 4]</td>
</tr>
<tr>
<td style="border: 2px solid black; padding: 5px;">3</td>
<td style="border: 2px solid black; padding: 5px;">[3, 4]</td>
</tr>
<tr>
<td style="border: 2px solid black; padding: 5px;">4</td>
<td style="border: 2px solid black; padding: 5px;">[4]</td>
</tr>
<tr>
<td style="border: 2px solid black; padding: 5px;">5</td>
<td style="border: 2px solid black; padding: 5px;">[]</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p><strong>示例 2</strong></p>
<pre>
<b>输入:</b>nums = [1,2,4,3]
<b>输出:</b>5
</pre>
<table style="border: 2px solid black; border-collapse: collapse;">
<thead>
<tr>
<th style="border: 2px solid black; padding: 5px;">Operation</th>
<th style="border: 2px solid black; padding: 5px;">Array</th>
</tr>
</thead>
<tbody>
<tr>
<td style="border: 2px solid black; padding: 5px;">1</td>
<td style="border: 2px solid black; padding: 5px;">[2, 4, 3]</td>
</tr>
<tr>
<td style="border: 2px solid black; padding: 5px;">2</td>
<td style="border: 2px solid black; padding: 5px;">[4, 3]</td>
</tr>
<tr>
<td style="border: 2px solid black; padding: 5px;">3</td>
<td style="border: 2px solid black; padding: 5px;">[3, 4]</td>
</tr>
<tr>
<td style="border: 2px solid black; padding: 5px;">4</td>
<td style="border: 2px solid black; padding: 5px;">[4]</td>
</tr>
<tr>
<td style="border: 2px solid black; padding: 5px;">5</td>
<td style="border: 2px solid black; padding: 5px;">[]</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p><strong>示例 3</strong></p>
<pre>
<b>输入:</b>nums = [1,2,3]
<b>输出:</b>3
</pre>
<table style="border: 2px solid black; border-collapse: collapse;">
<thead>
<tr>
<th style="border: 2px solid black; padding: 5px;">Operation</th>
<th style="border: 2px solid black; padding: 5px;">Array</th>
</tr>
</thead>
<tbody>
<tr>
<td style="border: 2px solid black; padding: 5px;">1</td>
<td style="border: 2px solid black; padding: 5px;">[2, 3]</td>
</tr>
<tr>
<td style="border: 2px solid black; padding: 5px;">2</td>
<td style="border: 2px solid black; padding: 5px;">[3]</td>
</tr>
<tr>
<td style="border: 2px solid black; padding: 5px;">3</td>
<td style="border: 2px solid black; padding: 5px;">[]</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
<li><code>-10<sup>9&nbsp;</sup>&lt;= nums[i] &lt;= 10<sup>9</sup></code></li>
<li><code>nums</code>&nbsp;中的元素 <strong>互不相同</strong>&nbsp;</li>
</ul>