We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 5fb7995 commit 1fc4f28Copy full SHA for 1fc4f28
solution/0075.Sort Colors/Solution2.cpp
@@ -0,0 +1,19 @@
1
+// 三路partition算法(0ms)
2
+class Solution {
3
+public:
4
+ void sortColors(vector<int>& nums) {
5
+ vector<int>::iterator next_lower = nums.begin() ;
6
+ vector<int>::iterator next_cmp = nums.begin() ;
7
+ vector<int>::iterator next_bigger = nums.end()-1 ;
8
+
9
+ while (next_cmp <= next_bigger)
10
+ {
11
+ if (*next_cmp < 1)
12
+ swap(*next_lower++, *next_cmp++) ;
13
+ else if (*next_cmp > 1)
14
+ swap(*next_bigger--, *next_cmp) ;
15
+ else
16
+ ++next_cmp ;
17
+ }
18
19
+};
0 commit comments