Leetcode 280 Solution

This article provides solution to leetcode question 280 (wiggle-sort)

https://leetcode.com/problems/wiggle-sort

Solution

class Solution {
public:
    void wiggleSort(vector<int>& nums) {
        for (int i = 1; i < nums.size(); i++)
        {
            if (i % 2 == 1 && nums[i] < nums[i - 1] || i % 2 == 0 && nums[i] > nums[i - 1])
                swap(nums[i], nums[i - 1]);
        }
    }
};