@@ -47,7 +47,7 @@ https://leetcode-cn.com/problems/sort-colors/
4747
4848这种思路的时间复杂度:$O(n)$,需要遍历数组两次(Two pass)。
4949
50- ![ image] ( https://user-images.githubusercontent.com/12479470/83542989-4ef55100-a52e-11ea-9a49-a0e9443da5f4.png )
50+ ![ image] ( https://tva1.sinaimg.cn/large/0081Kckwly1gl0hievmxyj30kl0c1t9m.jpg )
5151
5252## 解法二 - 挡板法
5353
@@ -57,27 +57,27 @@ https://leetcode-cn.com/problems/sort-colors/
5757
5858形象地来说地话就是有两个挡板,这两个挡板实现我们不知道,我们的目标就是移动挡板到合适位置,并且使得挡板每一部分都是合适的颜色。
5959
60- ![ image] ( https://user-images.githubusercontent.com/12479470/83542469-9a5b2f80-a52d-11ea-990d-1b56623ba2c8.png )
60+ ![ image] ( https://tva1.sinaimg.cn/large/0081Kckwly1gl0hihivldj31660u0wnb.jpg )
6161
6262还是以题目给的样例来说,初始化挡板位置为最左侧和最右侧:
6363
64- ![ image] ( https://user-images.githubusercontent.com/12479470/83542548-b19a1d00-a52d-11ea-92aa-c2458d7fe178.png )
64+ ![ image] ( https://tva1.sinaimg.cn/large/0081Kckwly1gl0hijbh5nj31h80h475x.jpg )
6565
6666读取第一个元素是 2,它应该在右边,那么我们移动右边地挡板。
6767
68- ![ image] ( https://user-images.githubusercontent.com/12479470/83542598-c5de1a00-a52d-11ea-9095-c66e1ed20c8f.png )
68+ ![ image] ( https://tva1.sinaimg.cn/large/0081Kckwly1gl0hikpnjhj31s80j4421.jpg )
6969
7070> 带有背景色的圆圈 1 是第一步的意思。
7171
7272并将其和移动挡板后挡板右侧地元素进行一次交换,这意味着“被移动挡板右侧地元素已就位”。
7373
74- ![ image] ( https://user-images.githubusercontent.com/12479470/83542711-e9a16000-a52d-11ea-9226-5a385c26174c.png )
74+ ![ image] ( https://tva1.sinaimg.cn/large/0081Kckwly1gl0himlg5zj31iu0j8mz8.jpg )
7575
7676。。。
7777
7878整个过程大概是这样的:
7979
80- ![ ] ( https://tva1.sinaimg.cn/large/007S8ZIlly1ggssusgyj7j310m0l2td1 .jpg )
80+ ![ ] ( https://tva1.sinaimg.cn/large/0081Kckwly1gl0himzyeaj310m0l2wfs .jpg )
8181
8282这种思路的时间复杂度也是$O(n)$, 只需要遍历数组一次。
8383
@@ -144,4 +144,4 @@ class Solution:
144144
145145大家对此有何看法,欢迎给我留言,我有时间都会一一查看回答。更多算法套路可以访问我的 LeetCode 题解仓库:https://github.com/azl397985856/leetcode 。 目前已经 37K star 啦。
146146大家也可以关注我的公众号《力扣加加》带你啃下算法这块硬骨头。
147- ![ ] ( https://tva1.sinaimg.cn/large/007S8ZIlly1gfcuzagjalj30p00dwabs .jpg )
147+ ![ ] ( https://tva1.sinaimg.cn/large/0081Kckwly1gl0hinyr5cj30p00dwt9t .jpg )
0 commit comments