-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSort Colors.cpp
More file actions
34 lines (29 loc) · 736 Bytes
/
Copy pathSort Colors.cpp
File metadata and controls
34 lines (29 loc) · 736 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
class Solution {
public:
void sortColors(vector<int>& nums) {
std::ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int low=0;
int mid=0;
int high=nums.size()-1;
while(mid<=high)
{
switch(nums[mid])
{
case 0:
swap(nums[low],nums[mid]);
low++;
mid++;
break;
case 1:
mid++;
break;
case 2:
swap(nums[mid],nums[high]);
high--;
break;
}
}
}
};