#103. 数组偶奇分离
数组偶奇分离
Even Before Odd
Background
In a data organization task, we need to perform a special sorting on a set of numbers. For easier subsequent processing, all even numbers must precede all odd numbers.
Problem Description
Return an array that contains the exact same numbers as the given array, but rearranged so that all the even numbers come before all the odd numbers. Other than that, the numbers can be in any order. You may modify and return the given array, or make a new array.
Input Format
Input is given from Standard Input in the following format.
A single line containing a list of integers enclosed in square brackets
[], with numbers separated by spaces.
Output Format
Output to Standard Output in the following format.
A single line containing a list of integers enclosed in square brackets
[], with numbers separated by commas and spaces,.
Sample
[1 0 1 0 0 1 1]
[0, 0, 0, 1, 1, 1, 1]
[3 3 2]
[2, 3, 3]
[2 2 2]
[2, 2, 2]
Sample Explanation
For the sample input [1 0 1 0 0 1 1], the even numbers are , and the odd numbers are . Arranging all even numbers before all odd numbers yields [0, 0, 0, 1, 1, 1, 1]. The relative order within even or odd numbers is not specified.
Constraints
Time Limit: 1s Memory Limit: 1024KiB