Skip to content

Commit 77c44fb

Browse files
authored
Create 75. Sort Colors
1 parent 7a32954 commit 77c44fb

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

75. Sort Colors

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

0 commit comments

Comments
 (0)