mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-25 17:50:26 +08:00
131 lines
3.8 KiB
HTML
131 lines
3.8 KiB
HTML
<p>给你一个包含若干 <strong>互不相同</strong> 整数的数组 <code>nums</code> ,你需要执行以下操作 <strong>直到</strong><strong>数组为空</strong> :</p>
|
||
|
||
<ul>
|
||
<li>如果数组中第一个元素是当前数组中的 <strong>最小值</strong> ,则删除它。</li>
|
||
<li>否则,将第一个元素移动到数组的 <strong>末尾</strong> 。</li>
|
||
</ul>
|
||
|
||
<p>请你返回需要多少个操作使<em> </em><code>nums</code><em> </em>为空。</p>
|
||
|
||
<p> </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> </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> </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> </p>
|
||
|
||
<p><strong>提示:</strong></p>
|
||
|
||
<ul>
|
||
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
|
||
<li><code>-10<sup>9 </sup><= nums[i] <= 10<sup>9</sup></code></li>
|
||
<li><code>nums</code> 中的元素 <strong>互不相同</strong> 。</li>
|
||
</ul>
|