移除0


Submit solution

Points: 10
Time limit: 1.0s
Memory limit: 4M

Author:
Problem type
Allowed languages
C++
移除0

给定一个整数n和一个整数数组 nums,n表示nums数组里面元素的个数。将nums数组所有的 0 移动到数组的末尾,同时保持非零元素的相对顺序。

输入

第一行输入整数n
第二行输入n个整数,每个数字之间通过空格隔开

输出

移动0之后的数组nums

注意,你必须 原地 修改数组,不得创建数组的副本。
示例 1:
输入:
5
0 1 0 3 12
输出:
1 3 12 0 0
示例 2:
输入:
0

输出:

0
约束条件:

\(1 \le nums.length \le 10^4\)
\(-2^31 \le nums[i] \le 2^{31} - 1\)


Comments

There are no comments at the moment.