Skip to content

Commit 54951e2

Browse files
committed
Merge branch 'master' of github.com:PegasusWang/python_data_structures_and_algorithms
2 parents 635c2a5 + 42925cd commit 54951e2

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

docs/03_链表/linked_list.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class Node(object):
6767
- 看似我们反过来遍历双链表了。反过来从哪里开始呢?我们只要让 root 的 prev 指向 tail 节点,不就串起来了吗?
6868
- 直接删除节点,当然如果给的是一个值,我们还是需要查找这个值在哪个节点? - 但是如果给了一个节点,我们把它拿掉,直接让它的前后节点互相指过去不就行了?哇欧,删除就是 O(1) 了,两步操作就行啦
6969

70-
好,废话不多说,我们在视频里介绍怎么实现一个双链表 ADT。
70+
好,废话不多说,我们在视频里介绍怎么实现一个双链表 ADT。你可以直接在本项目的 `docs/03_链表/double_link_list.py` 找到代码。
7171
最后让我们看下它的时间复杂度:(这里 CircularDoubleLinkedList 取大写字母缩写为 cdll)
7272

7373
循环双端链表操作 | 平均时间复杂度 |
@@ -78,15 +78,23 @@ cdll.remove(node),注意这里参数是 node | O(1) |
7878
cdll.headnode() | O(1) |
7979
cdll.tailnode() | O(1) |
8080

81+
8182
# 小问题:
8283
- 这里单链表我没有实现 insert 方法,你能自己尝试实现吗? insert(value, new_value),我想在某个值之前插入一个值。你同样需要先查找,所以这个步骤也不够高效。
8384
- 你能尝试自己实现个 lru cache 吗?需要使用到我们这里提到的循环双端链表
85+
- 借助内置的 collections.OrderedDict,它有两个方法 popitem 和 move_to_end,我们可以迅速实现一个 LRU cache。请你尝试用 OrderedDict 来实现。
8486
- python 内置库的哪些数据结构使用到了本章讲的链式结构?
8587

88+
8689
# 相关阅读
8790

8891
[那些年,我们一起跪过的算法题- Lru cache[视频]](https://zhuanlan.zhihu.com/p/35175401)
8992

9093
# 勘误:
9194

9295
视频中 LinkedList.remove 方法讲解有遗漏, linked_list.py 文件已经修正,请读者注意。具体请参考 [fix linked_list & add gitigonre](https://github.com/PegasusWang/python_data_structures_and_algorithms/pull/3)。视频最后增加了一段勘误说明。
96+
97+
# Leetcode
98+
99+
这里有一道关于 LRU 的练习题你可以尝试下。
100+
[LRU Cache](https://leetcode.com/problems/lru-cache/description/)

docs/11_线性查找与二分查找/search.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ def test_binary_search():
110110
- 阅读 python 文档 itertools 相关模块和常见的几个函数 takewhile, dropwhile, from_iterable, count, tee 等用法
111111
- [每个程序员都应该会点形式化证明](https://zhuanlan.zhihu.com/p/35364999?group_id=967109293607129088)
112112

113+
113114
# Leetcode
114115

115-
找旋转过的排序数组中最小的数。 https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/description/
116+
[找旋转过的排序数组中最小的数 find-minimum-in-rotated-sorted-array](https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/description/)
117+
118+
[已排序的数组中找到第一和最后一个元素 find-first-and-last-position-of-element-in-sorted-array/](https://leetcode.com/problems/find-first-and-last-position-of-element-in-sorted-array/submissions/)

0 commit comments

Comments
 (0)