Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 77c44fb

Browse filesBrowse files
authored
Create 75. Sort Colors
1 parent 7a32954 commit 77c44fb
Copy full SHA for 77c44fb

File tree

1 file changed

+15
-0
lines changed
Filter options

1 file changed

+15
-0
lines changed

‎75. Sort Colors

Copy file name to clipboard
+15Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.