Mediumarraystwo-pointers
Move Zeros to the End
Time limit 2 s · Memory 64 MBAcceptance: —Solved by: 0
Statement
The first line contains n, the second line contains n integers. Move all zeros to the end of the array while keeping the relative order of the other elements. Print the result on one line separated by spaces.
Examples
Example 1
Input
5 0 1 0 3 12
Output
1 3 12 0 0
Example 2
Input
3 0 0 0
Output
0 0 0
Constraints
- 1 ≤ n ≤ 10^5
- -10^9 ≤ a_i ≤ 10^9