Move Zeros to End
Move all zeros in an array to the end while maintaining the relative order of non-zero elements.
Input format
The first line contains N. The second line contains N space-separated integers.
Output format
Print the array with all zeros moved to the end, non-zero order preserved.
Constraints
- Values fit in a 64-bit signed integer
- Trailing whitespace and a trailing newline are ignored by the judge
Read from stdin, write to stdout. Sample cases below show the exact format.
Sample cases
Example 1
Input
5
0 1 0 3 12Expected output
1 3 12 0 0Example 2
Input
3
0 0 0Expected output
0 0 0