yokostan / Leetcode-Solutions

Doing exercise on Leetcode. Carry on!
0 stars 3 forks source link

Leetcode #280. Wiggle Sort #242

Open yokostan opened 5 years ago

yokostan commented 5 years ago

This is super amazing:

class Solution {
    public void wiggleSort(int[] nums) {
        if (nums == null) return ;
        for (int i = 1; i < nums.length; i++) {
            if (i % 2 == 1 != nums[i] >= nums[i - 1]) {
                int temp = nums[i];
                nums[i] = nums[i - 1];
                nums[i - 1] = temp;
            }
        }
    }
}

This line if (i % 2 == 1 != nums[i] >= nums[i - 1]) is genius in that it contains two conditions in the same line!!