280 Wiggle Sort
Given an unsorted arraynums
, reorder it in-place such thatnums[0] <= nums[1] >= nums[2] <= nums[3]...
.
For example, givennums = [3, 5, 2, 1, 6, 4]
, one possible answer is[1, 6, 2, 5, 3, 4]
.
因为允许相等,所以难度不大,只要loop一次把小的放偶数位,大的放奇数位就ok了。
Last updated