Skip to content

Commit 9374ea3

Browse files
author
lucifer
committed
feat: $ 75 增加相关题目
1 parent 3592ea2 commit 9374ea3

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

problems/75.sort-colors.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,34 @@ class Solution:
114114

115115
```
116116

117-
**_复杂度分析_**
117+
**复杂度分析**
118118

119119
- 时间复杂度:$O(N)$
120120
- 空间复杂度:$O(1)$
121121

122+
## 相关题目
123+
124+
- [面试题 02.04. 分割链表](https://leetcode-cn.com/problems/partition-list-lcci/)
125+
126+
参考代码:
127+
128+
```py
129+
class Solution:
130+
def partition(self, head: ListNode, x: int) -> ListNode:
131+
l1 = cur = head
132+
while cur:
133+
if cur.val < x:
134+
cur.val, l1.val = l1.val, cur.val
135+
l1 = l1.next
136+
cur = cur.next
137+
return head
138+
```
139+
140+
**复杂度分析**
141+
142+
- 时间复杂度:$O(N)$,其中 N 为链表长度。
143+
- 空间复杂度:$O(1)$。
144+
122145
大家对此有何看法,欢迎给我留言,我有时间都会一一查看回答。更多算法套路可以访问我的 LeetCode 题解仓库:https://github.com/azl397985856/leetcode 。 目前已经 37K star 啦。
123146
大家也可以关注我的公众号《力扣加加》带你啃下算法这块硬骨头。
124147
![](https://tva1.sinaimg.cn/large/007S8ZIlly1gfcuzagjalj30p00dwabs.jpg)

0 commit comments

Comments
 (0)