Is [4 5 1 6 1 4] a reasonable answer? Please tell me why it did not pass....


  • 0
    C

    Here is my code:

    public static void wiggleSort(int[] nums) {
            if (nums == null || nums.length == 0) {
                return;
            }
            
            int[] sorted = Arrays.copyOf(nums, nums.length);
            Arrays.sort(sorted);
            int n = nums.length, m = n | 1;
            for (int i = 0; i <= n / 2; i++) {
            	if (2 * i < n) {
            		nums[2 * i] = sorted[n / 2 - i];
            	}
            	if (n / 2 + 1 + i < n) {
            		nums[1 + 2 * i] = sorted[n / 2 + 1 + i];
            	}
            }
        }

Log in to reply
 

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