Skip to content

Latest commit

 

History

History
14 lines (13 loc) · 310 Bytes

324. Wiggle Sort II.md

File metadata and controls

14 lines (13 loc) · 310 Bytes
class Solution {
public:
    void wiggleSort(vector<int>& nums) {
        sort(nums.begin(), nums.end());
        int n = nums.size(), i = (n + 1) / 2 - 1, j = n - 1;
        vector<int> v = nums;
        for (int k = 0; k < n; ++k) {
            nums[k] = k & 1 ? v[j--] : v[i--];
        }
    }
};