对原数组排序,得到排序后的辅助数组tmp
对原数组的偶数位下标填充tmp的末尾元素
对原数组的奇数位下标填充tmp的末尾元素
算法复杂度是快速排序的复杂度O(NlogN)。
class Solution(object):
"""
@param {int[]} nums a list of integer
@return nothing, modify nums in-place instead
"""
def wiggleSort(self, nums):
# Write your code here
if not nums or len(nums) == 1:
return nums
tmp = sorted(nums)
for i in range(1, len(nums), 2):
nums[i] = tmp.pop()
for i in range(0, len(nums), 2):
nums[i] = tmp.pop()