#324

Wiggle Sort II

expert · 1070 · lc medium +32 · verified · 37% accepted · 3,245 likes · top 15%

play →

Description

Given an integer array nums, reorder it in-place such that nums[0] < nums[1] > nums[2] < nums[3]....

You may assume the input array always has a valid answer.

Example 1:

Input: nums = [1,5,1,1,6,4]
Output: [1,6,1,5,1,4]
Explanation: [1,4,1,5,1,6] is also accepted.

Example 2:

Input: nums = [1,3,2,2,3,1]
Output: [2,3,1,3,1,2]

Code

1
2
3
4
5
6