Skip to content

Commit 82fb652

Browse files
authored
Create 75.cpp
1 parent 0424b7a commit 82fb652

File tree

1 file changed

+22
-0
lines changed
  • leetcode/cpp/Two Pointer

1 file changed

+22
-0
lines changed

leetcode/cpp/Two Pointer/75.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 low=0,mid=0,high=nums.size()-1;
5+
while(mid<=high){
6+
7+
if(nums[mid]==0)
8+
{
9+
swap(nums[low],nums[mid]);
10+
low++,mid++;
11+
}
12+
else if(nums[mid]==1)
13+
{
14+
mid++;
15+
}
16+
else{
17+
swap(nums[mid],nums[high]);
18+
high--;
19+
}
20+
}
21+
}
22+
};

0 commit comments

Comments
 (0)