← 返回 jpmorgan 的题目列表Move Zeroes
类型:online_judge
Problem: Move Zeroes
Given an integer array nums, move all 0s to the end while maintaining the relative order of the non-zero elements.
Try to modify the array in-place instead of copying a new array as the main result.
Input Format
First line: integer n, the length of the array
Second line: n integers representing nums
Output Format
Print the modified array, separated by spaces
Constraints
1 <= n <= 10^4
-2^31 <= nums[i] <= 2^31 - 1
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