1 public class Solution {
 2     public void wiggleSort(int[] nums) {
 3         Arrays.sort(nums);
 4         
 5         int[] result = new int[nums.length];
 6         int bound = nums.length % 2 == 1 ? nums.length / 2 : nums.length / 2 - 1;
 7         int i = bound;
 8         int j = nums.length - 1;
 9         int index = 0;
10         
11         while (index < nums.length) {
12             result[index++] = nums[i--];
13             if (j > bound) {
14                 result[index++] = nums[j--];
15             }
16         }
17         
18         for (i = 0; i < nums.length; i++) {
19             nums[i] = result[i];
20         }
21     }
22 }

1. Use backward arrangement in case of [4, 5, 5, 6].

posted on 2016-07-02 06:56  keepshuatishuati  阅读(121)  评论(0编辑  收藏  举报