My Python Solution with extra space, but easy to understand


  • 0
    W
    class Solution(object):
        def wiggleSort(self, nums):
            sorted_nums = sorted(nums)
            for i in range(len(nums)):
                if i % 2 == 0:
                    nums[i] = sorted_nums[i/2]
                else:
                    nums[i] = sorted_nums[-i/2]
    

    it takes O(n) extra space.


Log in to reply
 

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