Leetcode 280 Solution
This article provides solution to leetcode question 280 (wiggle-sort)
Access this page by simply typing in "lcs 280" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
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]);
}
}
};