Description
Given an integer array nums, move all the even integers at the beginning of the array followed by all the odd integers. Return any array that satisfies this condition.
Examples
Input:
nums = [3,1,2,4]Output:
[2,4,3,1]Explanation:
Evens first, then odds.
Input:
nums = [1,3,5,7]Output:
[1,3,5,7]Explanation:
All numbers are odd, so they remain in their original positions since there are no even numbers to move to the beginning.
Input:
nums = [8,6,0,2,9,11]Output:
[8,6,0,2,9,11]Explanation:
The first four numbers (8,6,0,2) are all even and already at the beginning, followed by the odd numbers (9,11), so the array is already properly sorted by parity.
Constraints
- •
1 ≤ nums.length ≤ 5000 - •
0 ≤ nums[i] ≤ 5000