Sort Array By Parity II
In this lab, you will be given an array of integers
nums, where half of the integers in
nums are odd, and the other half are even. Your task is to sort the array so that whenever
nums[i] is odd,
i is odd, and whenever
nums[i] is even,
i is even. You should return any answer array that satisfies this condition.
[4,2,5,7], a valid output would be
[4,5,2,7]. Other valid outputs like
[2,7,4,5]would also be accepted.
[2,3], the output would be
2 <= nums.length <= 2 * 104
- Half of the integers in
0 <= nums[i] <= 1000
Follow Up: Could you solve it in-place?
- Export the function
- The exported
sortArrayByParityIIfunction should sort the input array according to the parity condition described.
- The function
sortArrayByParityIIshould work with the given constraints and edge cases.