Advertisement
nikunjsoni

75

Apr 14th, 2021
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.34 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     void sortColors(vector<int>& nums) {
  4.         int n=nums.size(), last, first;
  5.         last = n-1; first = 0;
  6.         for(int i=0; i<n; i++){
  7.             while(nums[i] == 2 && i<last) swap(nums[i], nums[last--]);
  8.             while(nums[i] == 0 && i>first) swap(nums[i], nums[first++]);
  9.         }    
  10.     }
  11. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement