Skip to content

Commit 71b3694

Browse files
authored
Create 0075-Sort-colors.cpp
1 parent 2056c01 commit 71b3694

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

cpp/0075-Sort-colors.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution {
2+
public:
3+
void sortColors(vector<int>& nums) {
4+
int p1=0,p2=nums.size()-1;
5+
for(int i=p1;i<=p2;i++)
6+
{
7+
if(nums[i]==0)
8+
{
9+
swap(nums[i],nums[p1]);
10+
p1++;
11+
}
12+
if(nums[i]==2)
13+
{
14+
swap(nums[i],nums[p2]);
15+
p2--;
16+
i--;
17+
}
18+
}
19+
20+
21+
}
22+
};

0 commit comments

Comments
 (0)