Skip to content

Commit fb99aec

Browse files
committed
Update 25. 颜色分类.md
1 parent a4e8c5e commit fb99aec

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

25. 颜色分类.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
***给定一个包含红色、白色和蓝色、共 n 个元素的数组 nums ,原地对它们进行排序,使得相同颜色的元素相邻,并按照红色、白色、蓝色顺序排列。我们使用整数 0、 1 和 2 分别表示红色、白色和蓝色。***
22

33
```
4-
单指针+对数组进行两次遍历。在第一次遍历中,我们将数组中所有的 0 交换到数组的头部。在第二次遍历中,我们将数组中所有的 1 交换到头部的 0 之后。此时,所有的 2 都出现在数组的尾部,这样我们就完成了排序。
4+
#单指针+对数组进行两次遍历。
5+
#在第一次遍历中,我们将数组中所有的 0 交换到数组的头部。
6+
#在第二次遍历中,我们将数组中所有的 1 交换到头部的 0 之后。此时,所有的 2 都出现在数组的尾部,这样我们就完成了排序。
7+
58
class Solution:
69
def sortColors(self, nums: List[int]) -> None:
710
"""
@@ -21,7 +24,9 @@ class Solution:
2124
```
2225

2326
```
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+
2530
class Solution:
2631
def sortColors(self, nums: List[int]) -> None:
2732
"""

0 commit comments

Comments
 (0)