Short java solution using sort


  • 0
    Y
     public void wiggleSort(int[] nums) {
        Arrays.sort(nums);
        int len = nums.length;
        if(len<3) return;
        for(int i=2;i<nums.length;i+=2){
            int tem = nums[i];
            nums[i] = nums[i-1];
            nums[i-1] = tem;
        }
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.