Skip to content

Commit 8152713

Browse files
committed
python dict implement cache
1 parent cd14876 commit 8152713

File tree

1 file changed

+1
-0
lines changed
  • docs/19_python内置常用算法和数据结构

1 file changed

+1
-0
lines changed

docs/19_python内置常用算法和数据结构/builtins.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ def maxheapval(h):
268268
python3 functools 模块的 cache 功能和 lru_cache(maxsize=None) 一样,不过更加轻量更快。在记忆化递归搜索的时候很方便。
269269
注意这里的参数 `maxsize=None` 一定要设置为 None,否则默认的 maxsize=128。
270270
举一个力扣上的例子,如果不加 cache 递归函数因为会大量重复计算直接超时,但是加一个装饰器就可以通过。
271+
当然了如果你用 python2 没有这个装饰器,你可以直接用 python 的 dict 来实现。(存在就返回,否则计算结果保存到 dict 里)
271272

272273
```py
273274
"""

0 commit comments

Comments
 (0)