Simple Java Solution


  • 0
    K
    public void wiggleSort(int[] nums) {
        boolean larger = true;
        for (int i = 1; i < nums.length; i++) {
            if (nums[i] > nums[i-1] != larger) {
                nums[i] ^= nums[i-1];
                nums[i-1] ^= nums[i];
                nums[i] ^= nums[i-1];
            }
            larger = !larger;
        }
    }

Log in to reply
 

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