Skip to content

Commit 026e84e

Browse files
authoredOct 13, 2022
Create SortColors.cpp
1 parent 5e5b453 commit 026e84e

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
 

‎easy/SortColors.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// 75. Sort Colors
2+
class Solution {
3+
public:
4+
void sortColors(vector<int>& nums) {
5+
int count0 =0, count1=0, count2=0;
6+
for(int i=0;i<nums.size();i++)
7+
{
8+
if(nums[i]==0)
9+
count0++;
10+
else if(nums[i]==1)
11+
count1++;
12+
else
13+
count2++;
14+
}
15+
16+
int i=0;
17+
while(count0>0)
18+
{
19+
nums[i++]=0;
20+
count0--;
21+
}
22+
23+
while(count1>0)
24+
{
25+
nums[i++]=1;
26+
count1--;
27+
}
28+
29+
while(count2>0)
30+
{
31+
nums[i++]=2;
32+
count2--;
33+
}
34+
35+
}
36+
};

0 commit comments

Comments
 (0)
Please sign in to comment.