Skip to content

Commit

Permalink
Create 0075-Sort-colors.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
ektagoel-12 authored Jan 3, 2023
1 parent 2056c01 commit 71b3694
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions cpp/0075-Sort-colors.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class Solution {
public:
void sortColors(vector<int>& nums) {
int p1=0,p2=nums.size()-1;
for(int i=p1;i<=p2;i++)
{
if(nums[i]==0)
{
swap(nums[i],nums[p1]);
p1++;
}
if(nums[i]==2)
{
swap(nums[i],nums[p2]);
p2--;
i--;
}
}


}
};

0 comments on commit 71b3694

Please sign in to comment.