← 返回 bytedance 的题目列表Move Zeroes
类型:online_judge
Given an integer array nums, move all 0's to the end of it while maintaining the relative order of the non-zero elements.
Requirements:
Do it in-place.
Minimize the total number of operations.
Input
Line 1: integer n.
Line 2: n integers, the array nums.
Output
One line: the resulting array, space-separated.
Constraints
0 <= n <= 2*10^5
-10^9 <= nums[i] <= 10^9
Example
Input:
5
0 1 0 3 12
Output:
1 3 12 0 0
Example
Input
5
0 1 0 3 12
Output
1 3 12 0 0