classSolution{public:voidwiggleSort(vector<int>&nums){if(nums.size()<2)return;intn=nums.size(),m=(n+1)/2;vector<int>copy=nums;// find mediannth_element(nums.begin(),nums.begin()+m,nums.end());intmid=nums[m];threeWay(copy,mid);// if odd pick from right partition// if even pick from left partitionfor(inti=0;i<nums.size();++i){nums[i]=i&1?copy[--n]:copy[--m];}}// https://en.wikipedia.org/wiki/Dutch_national_flag_problemvoidthreeWay(vector<int>&A,intmid){inti=0,j=0,k=A.size()-1;while(j<=k){if(A[j]<mid){swap(A[i],A[j]);i++;j++;}elseif(A[j]>mid){swap(A[j],A[k]);k--;}else{j++;}}}};