0280. Wiggle Sort
https://leetcode.com/problems/wiggle-sort
Description
Given an integer array nums
, reorder it such that nums[0] <= nums[1] >= nums[2] <= nums[3]...
.
You may assume the input array always has a valid answer.
Example 1:
Example 2:
Constraints:
1 <= nums.length <= 5 * 104
0 <= nums[i] <= 104
It is guaranteed that there will be an answer for the given input
nums
.
Follow up: Could you do it without sorting the array?
ac1: in-place odd/even check
This is kinda "aha" brain teaser. See proof: https://leetcode.com/problems/wiggle-sort/discuss/71693/My-explanations-of-the-best-voted-Algo/112986.
ac2: quickselect partition
Same as 324-Wiggle Sort II
Last updated