Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- void swap(int &a,int &b)
- {
- int temp = a;
- a = b;
- b = temp;
- }
- void sortColors(vector<int>& nums) {
- int i=0,k=0,j=nums.size()-1;
- while(k<=j)
- {
- if(nums[k]==0)
- {
- swap(nums[i],nums[k]);
- i++;
- k++;
- }
- else if(nums[k]==1)
- {
- k++;
- }
- else
- {
- swap(nums[k],nums[j]);
- j--;
- }
- }
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment