###### LeetCode Wiggle Sort II

Description:

Given an unsorted array nums, reorder it such that nums[0] < nums[1] > nums[2] < nums[3]....

Example:
(1) Given nums = [1, 5, 1, 1, 6, 4], one possible answer is [1, 4, 1, 5, 1, 6]
(2) Given nums = [1, 3, 2, 2, 3, 1], one possible answer is [2, 3, 1, 3, 1, 2].

Solution:

<span style="font-size:18px;">import java.util.*;

public class Solution {
public void wiggleSort(int[] nums) {
if (nums == null)
return;

int n = nums.length;
int left = n;
int mid = (n - 1) / 2 + 1;

Arrays.sort(nums);
int neoNums[] = new int[n];

for (int i = 0; i < n; i++)
neoNums[i] = (i & 1) == 0 ? nums[--mid] : nums[--left];

for (int i = 0; i < n; i++)
nums[i] = neoNums[i];

return;
}

public static void main(String[] args) {
int arr[] = { 0, 1, 2, 3, 4 };
Solution s = new Solution();
s.wiggleSort(arr);
}
}</span>

#### [LeetCode 324] Wiggle Sort II

2016-01-13 17:18:23

#### [leetcode] 324. Wiggle Sort II 解题报告

2016-05-07 12:17:59

#### 324. Wiggle Sort II 摆动排序

2016-07-27 18:05:57

#### [leetcode] - 324. Wiggle Sort II

2016-01-29 13:40:50

#### LeetCode 324. Wiggle Sort II（摇摆排序）

2016-04-26 04:48:49

#### Wiggle Sort II

2016-02-26 10:17:10

#### leetcode 280: Wiggle Sort

2015-09-26 07:44:26

#### [leetcode] 280. Wiggle Sort 解题报告

2016-03-13 03:29:12

#### leecode 解题总结：324. Wiggle Sort II

2017-02-28 21:26:01

#### LeetCode 280. Wiggle Sort（摇摆排序）

2016-04-14 07:27:02

## 不良信息举报

LeetCode Wiggle Sort II