Let the code explain itself, JAVA, short and powerful


  • 0
    public class Solution {
        public void wiggleSort(int[] nums) {
            for (int i = 1; i < nums.length; i ++) {
                if ((i % 2 == 1 && nums[i - 1] > nums[i]) || (i % 2 == 0 && nums[i - 1] < nums[i])) {
                    nums[i - 1] ^= nums[i];
                    nums[i] ^= nums[i - 1];
                    nums[i - 1] ^= nums[i];
                }
            }
        }
    }
    

Log in to reply
 

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