← 返回 meta 的题目列表Wiggle Sort
类型:online_judge
meta
Given an integer array nums, order the array such that nums[0] <= nums[1] >= nums[2] <= nums[3]... and so on. Implement this function and return the modified array.
Example
Example 1:
Input: nums = [3, 5, 2, 1, 6, 4]
Output: [3, 5, 1, 6, 2, 4]
Example 2:
Input: nums = [1, 2, 3, 4, 5]
Output: [1, 3, 2, 5, 4]
Constraints
The length of the array is [1, 10000].
nums[i] is a 32-bit signed integer.
Example
Input
3
3 5 2 1 6 4