Advertisement
nikunjsoni

280

Jun 28th, 2021
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.37 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     void wiggleSort(vector<int>& nums) {
  4.         for(int i=0; i<nums.size()-1; i++){
  5.             if(i%2 == 0){
  6.                 if(nums[i]>nums[i+1])
  7.                     swap(nums[i], nums[i+1]);
  8.             }
  9.             else{
  10.                 if(nums[i]<nums[i+1])
  11.                     swap(nums[i], nums[i+1]);
  12.             }
  13.         }
  14.     }
  15. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement