A/C Python solution, easy to understand, beat 15%


  • 0
    W
    def wiggleSort(self, nums):
        #print "nums = ", nums
        nums.sort()
        #print "after sort, nums = ", nums
    
        for i in range(len(nums)):
            if i > 1 and i % 2 == 0:
                #print "i = ", i, "nums[i] = ", nums[i]
    
                nums[i-1], nums[i] = nums[i], nums[i-1]
    
        #print "in the end, nums = ", nums

Log in to reply
 

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