mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
33 lines
903 B
HTML
33 lines
903 B
HTML
<p>给定一个数组 <code>nums</code>,编写一个函数将所有 <code>0</code> 移动到数组的末尾,同时保持非零元素的相对顺序。</p>
|
|
|
|
<p><strong>请注意</strong> ,必须在不复制数组的情况下原地对数组进行操作。</p>
|
|
|
|
<p> </p>
|
|
|
|
<p><strong>示例 1:</strong></p>
|
|
|
|
<pre>
|
|
<strong>输入:</strong> nums = <code>[0,1,0,3,12]</code>
|
|
<strong>输出:</strong> <code>[1,3,12,0,0]</code>
|
|
</pre>
|
|
|
|
<p><strong>示例 2:</strong></p>
|
|
|
|
<pre>
|
|
<strong>输入:</strong> nums = <code>[0]</code>
|
|
<strong>输出:</strong> <code>[0]</code></pre>
|
|
|
|
<p> </p>
|
|
|
|
<p><strong>提示</strong>:</p>
|
|
<meta charset="UTF-8" />
|
|
|
|
<ul>
|
|
<li><code>1 <= nums.length <= 10<sup>4</sup></code></li>
|
|
<li><code>-2<sup>31</sup> <= nums[i] <= 2<sup>31</sup> - 1</code></li>
|
|
</ul>
|
|
|
|
<p> </p>
|
|
|
|
<p><b>进阶:</b>你能尽量减少完成的操作次数吗?</p>
|