File tree Expand file tree Collapse file tree 1 file changed +12
-12
lines changed
docs/19_python内置常用算法和数据结构 Expand file tree Collapse file tree 1 file changed +12
-12
lines changed Original file line number Diff line number Diff line change 12
12
13
13
下边我列了一个常用 python 内置数据结构和算法的表格,如果有遗漏可以在 issue 中提出。确保你了解这些数据结构和算法的使用以及时间、空间复杂度。
14
14
15
- | 数据结构/算法 | 语言内置 | 内置库 |
16
- | ---------------| ---------------------------------| ---------------------------------------------------------------|
17
- | 线性结构 | list(列表)/tuple(元祖) | array(数组,不常用)/collections.namedtuple |
18
- | 链式结构 | | collections.deque(双端队列) |
19
- | 字典结构 | dict(字典) | collections.Counter(计数器)/OrderedDict(有序字典)/defaultdict |
20
- | 集合结构 | set(集合)/frozenset(不可变集合) | |
21
- | 排序算法 | sorted | |
22
- | 二分算法 | | bisect模块 |
23
- | 堆算法 | | heapq模块 |
24
- | 优先级队列 | | queue.PriorityQueue |
25
- | 缓存算法 | | functools.lru_cache(Least Recent Used, python3) |
15
+ | 数据结构/算法 | 语言内置 | 内置库 |
16
+ | ---------------| ---------------------------------| ------------------------------------------------------------------------- |
17
+ | 线性结构 | list(列表)/tuple(元祖) | array(数组,不常用)/collections.namedtuple |
18
+ | 链式结构 | | collections.deque(双端队列) |
19
+ | 字典结构 | dict(字典) | collections.Counter(计数器)/OrderedDict(有序字典)/defaultdict(默认字典) |
20
+ | 集合结构 | set(集合)/frozenset(不可变集合) | |
21
+ | 排序算法 | sorted | |
22
+ | 二分算法 | | bisect模块 |
23
+ | 堆算法 | | heapq模块 |
24
+ | 优先级队列 | | queue.PriorityQueue/heapq |
25
+ | 缓存算法 | | functools.lru_cache(Least Recent Used, python3) |
26
26
27
27
# 一些坑
28
28
29
- 如果你经常使用 python2 or python3 刷题(比如力扣leetcode),有一些坑或者技巧需要注意:
29
+ 如果你使用 python2 or python3 刷题(比如力扣leetcode),有一些坑或者技巧需要注意:
30
30
31
31
- python3 和 python2 的 dict 有所用不同,python3.7 之后的 dict 会保持插入顺序, python2 不要依赖 dict 迭代顺序,请使用 OrderedDict
32
32
- 正确初始化一个二维数组:` dp = [[0 for _ in range(col)] for _ in range(row)] ` ,不要用 ` dp = [[0] * n] * m ` , 否则里边都
You can’t perform that action at this time.
0 commit comments