knakul853

Untitled

Jul 11th, 2020
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None | 0 0
  1. /**
  2. knakul853
  3. **/
  4. class Solution {
  5. public:
  6.     void sortColors(vector<int>& nums)
  7.     {
  8.         int low = 0;
  9.         int high=nums.size()-1;
  10.        
  11.         int i=0;
  12.         while(i<= high)
  13.         {
  14.             if(nums[i]==0){
  15.                 swap(nums[i] , nums[low]);
  16.                 i++;low++;continue;
  17.             }
  18.             if(nums[i]==2)
  19.             {
  20.                 swap(nums[i] , nums[high--]);continue;
  21.             }
  22.             i++;
  23.         }
  24.        
  25.     }
  26. };
Add Comment
Please, Sign In to add comment