Loading...
You are given an integer array nums.
Rearrange its values so that:
The parity pattern of the array (which positions hold odd values and which hold even values) must not change.
Return the resulting array.
Input: nums = [9, 4, 3, 8, 7, 2, 5]
Output: [3, 8, 5, 4, 7, 2, 9]
Explanation: The odd values 9, 3, 7, 5 (at positions 0, 2, 4, 6) become
3, 5, 7, 9 in ascending order. The even values 4, 8, 2 (at positions 1, 3, 5)
become 8, 4, 2 in descending order.
Input: nums = [6, 6, 0]
Output: [6, 6, 0]
Explanation: There are no odd values; the even values sorted descending keep
the same layout.
nums.length ≤105nums[i] ≤109Click "Run" to test with sample cases or "Submit" to run all tests.