```
public void wiggleSort(int[] nums) {
Arrays.sort(nums); // time O(NlogN)
if (nums.length <= 2)
return;
int[] tmp = new int[nums.length / 2]; // space O(N)
System.arraycopy(nums, nums.length - nums.length / 2, tmp, 0, tmp.length); //store the right half
for (int i = nums.length - nums.length / 2 - 1; i >= 0; i--) {
nums[i * 2] = nums[i]; // move the numbers of left half to their place
}
for (int j = 0; j < tmp.length; j++) {
nums[2 * j + 1] = tmp[j];
}
}
```