Python O(N) Solution


  • 0
    def wiggleSort(self, nums):
        n, i = len(nums), 0
        for i in range(n-1):
            curr, next = nums[i], nums[i+1]
            if i % 2 == 0 and next < curr:
                nums[i], nums[i+1] = nums[i+1], nums[i]
            elif i % 2 == 1 and next > curr:
                    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.