---
description: LeetCode 324
---

# Wiggle Sort

```python
def wiggleSort(nums):
    """
    :type nums: List[int]
    :rtype: void Do not return anything, modify nums in-place instead.
    """
    nums.sort()

    base = len(nums[::2])
    arr1 = nums[:base]
    arr2 = nums[base:]
    nums[0::2] = arr1[::-1]
    nums[1::2] = arr2[::-1]
    # 到著放的原因是 中段前配尾段 前段配中段後 避免中間相同重複
    # [1, 2, 3]
    # [3, 3, 5]
    return nums
    # res = [3, 5, 2, 3, 1, 3]
wiggleSort([1, 2, 3, 3, 3, 5])
```
