324. Wiggle Sort II 發表於 2023-02-13 | 分類於 leetcode problemsolution1234567891011121314class Solution {public: void wiggleSort(vector<int>& nums) { sort(nums.begin(), nums.end()); int n = nums.size(); int l = (n-1)/2, r = n-1; vector<int> ret(n,0); for(int i=0;i<n;++i){ if(i%2==0) ret[i] = nums[l--]; else ret[i] = nums[r--]; } nums = ret; }}; analysis time complexity O(nlogn) space complexity O(n)