@happyLucia

Hi!

When I tried your case, the OJ just printed out "[1,1,1,1,1,2,2,2,2,2]".

But my another solution may work.

class Solution {
public:
void wiggleSort(vector<int>& nums) {
if (nums.empty()) {
return;
}
sort(nums.begin(), nums.end());
swap(nums.back(), nums[nums.size() / 2]);
if (nums.size() % 2) {
wiggleSort(nums, 0, nums.size() - 2);
} else {
wiggleSort(nums, 0, nums.size() - 1);
}
}
private:
void wiggleSort(vector<int>& nums, int l, int r) {
if (l < r - 1) {
int _size = r - l + 1, i = l + _size / 4, mid = l + _size / 2, j = l + 3 * _size / 4;
reverse(nums.begin() + i, nums.begin() + mid);
reverse(nums.begin() + mid, nums.begin() + j);
reverse(nums.begin() + i, nums.begin() + j);
wiggleSort(nums, l, l + 2 * (i - l) - 1);
wiggleSort(nums, l + 2 * (i - l), r);
}
}
};