Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6240b5e

Browse files
Update README.md
1 parent 1e41a3b commit 6240b5e

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

‎README.md‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,6 @@ class Solution:
282282
```
283283
- 7 or 9 等于 7
284284
- None and 7 等于 None
285-
- sorted用在这里为了保证 l1 的值小于等于 l2 的值
286285
## [23. Merge k Sorted Lists 4行](https://leetcode.com/problems/merge-k-sorted-lists/)
287286
```python
288287
# Definition for singly-linked list.
@@ -5523,6 +5522,23 @@ class Solution:
55235522
- 空间复杂度:O(logN)
55245523
- x^4 = x^2 ** x^2, x^5 = x^2 * x^2 * x, 借此方法可以缩减计算量
55255524

5525+
**总结**
5526+
#### [21. 合并两个有序链表](https://leetcode-cn.com/problems/merge-two-sorted-lists/)
5527+
```python
5528+
# Definition for singly-linked list.
5529+
# class ListNode:
5530+
# def __init__(self, x):
5531+
# self.val = x
5532+
# self.next = None
5533+
5534+
class Solution:
5535+
def mergeTwoLists(self, l1: ListNode, l2: ListNode) -> ListNode:
5536+
if l1 and l2:
5537+
if l1.val > l2.val: l1, l2 = l2, l1
5538+
l1.next = self.mergeTwoLists(l1.next, l2)
5539+
return l1 or l2
5540+
```
5541+
55265542
# 常用技巧总结
55275543
- set 中的 in 操作时间复杂度为 O(1)
55285544
- dict.get 可以设置预设值,避免取到不存在的 key 时报错

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /