Given an array
A of non-negative integers, return an array consisting of all the even elements of
A, followed by all the odd elements of
You may return any answer array that satisfies this condition.
1 <= A.length <= 5000
0 <= A[i] <= 5000
- Approach 1: Sort
Use a custom comparator when sorting, to sort by parity.
Time Complexity: O(NlogN), Space Complexity: O(N)
- Approach 2: Two Pass
Write all the even elements first, then write all the odd elements.
Time Complexity: O(N), Space Complexity: O(N)
- Approach 3: In-Place
Time Complexity: O(N), Space Complexity: O(1)