Python O(N) Solution


  • 0
    F
        def wiggleSort(self, nums):
            p1 = 0
            p2 = 1
            while p2 < len(nums):
                s,l = (nums[p1], nums[p2]) if nums[p1] <= nums[p2] else (nums[p2], nums[p1])
                if p1%2 == 0:
                    nums[p1] = s 
                    nums[p2] = l 
                else:
                    nums[p1] = l 
                    nums[p2] = s
                p1 = p1 + 1 
                p2 = p2 + 1
    

Log in to reply
 

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