File tree Expand file tree Collapse file tree 1 file changed +7
-2
lines changed Expand file tree Collapse file tree 1 file changed +7
-2
lines changed Original file line number Diff line number Diff line change 1
1
*** 给定一个包含红色、白色和蓝色、共 n 个元素的数组 nums ,原地对它们进行排序,使得相同颜色的元素相邻,并按照红色、白色、蓝色顺序排列。我们使用整数 0、 1 和 2 分别表示红色、白色和蓝色。***
2
2
3
3
```
4
- 单指针+对数组进行两次遍历。在第一次遍历中,我们将数组中所有的 0 交换到数组的头部。在第二次遍历中,我们将数组中所有的 1 交换到头部的 0 之后。此时,所有的 2 都出现在数组的尾部,这样我们就完成了排序。
4
+ #单指针+对数组进行两次遍历。
5
+ #在第一次遍历中,我们将数组中所有的 0 交换到数组的头部。
6
+ #在第二次遍历中,我们将数组中所有的 1 交换到头部的 0 之后。此时,所有的 2 都出现在数组的尾部,这样我们就完成了排序。
7
+
5
8
class Solution:
6
9
def sortColors(self, nums: List[int]) -> None:
7
10
"""
@@ -21,7 +24,9 @@ class Solution:
21
24
```
22
25
23
26
```
24
- 双指针Ref:https://leetcode.cn/problems/sort-colors/solution/yan-se-fen-lei-by-leetcode-solution/
27
+ #双指针
28
+ #Ref:https://leetcode.cn/problems/sort-colors/solution/yan-se-fen-lei-by-leetcode-solution/
29
+
25
30
class Solution:
26
31
def sortColors(self, nums: List[int]) -> None:
27
32
"""
You can’t perform that action at this time.
0 commit comments