File tree Expand file tree Collapse file tree 1 file changed +6
-5
lines changed
docs/19_python内置常用算法和数据结构 Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Original file line number Diff line number Diff line change @@ -233,7 +233,7 @@ def maxheappop(h):
233
233
234
234
def maxheapval (h ):
235
235
return - h[0 ]
236
- ``````
236
+ ```
237
237
238
238
# lru_cache/cache 优化记忆化搜索
239
239
@@ -245,7 +245,8 @@ python3 functools 模块的 cache 功能和 lru_cache(maxsize=None) 一样,不
245
245
[337] 打家劫舍 III
246
246
https://leetcode-cn.com/problems/house-robber-iii/description/
247
247
"""
248
- from functools import cache, lru_cache # cache 等价于 functools.lru_cache(maxsize=None)
248
+ # cache 等价于 functools.lru_cache(maxsize=None), 不过python3版本低可能没有 cache 只有 lru_cache
249
+ from functools import cache, lru_cache
249
250
250
251
251
252
class Solution (object ):
@@ -255,7 +256,7 @@ class Solution(object):
255
256
:type root: TreeNode
256
257
:rtype: int
257
258
"""
258
- # @lru_cache(maxsize=None)
259
+ # @lru_cache(maxsize=None) # 注意如果 python3 版本不是很新的话,只能用 lru_cache(maxsize=None)
259
260
@cache # NOTE : 不加 cache 会直接超时,就只能用动态规划了
260
261
def dfs (root ):
261
262
if root is None :
@@ -425,11 +426,11 @@ class Solution(object):
425
426
return n+1
426
427
```
427
428
428
- # 兼容提交格式
429
+ # 兼容代码提交格式
429
430
430
431
注意牛客网有两种模式,一种是和 leetcode 一样的提交(无需处理输入),只需要提交核心代码。
431
432
一种是 ACM 模式,还需要自己处理输入和输出。
432
- 建议使用这种兼容写法,同样的题目可以同时提交到 牛客和leetcode 。
433
+ 建议使用这种兼容写法,同样的题目可以同时提交到 牛客、leetcode 和 acwing(python3) 。
433
434
这道题目为例子 [ 679] 奖品分配 https://www.acwing.com/problem/content/681/
434
435
435
436
``` py
You can’t perform that action at this time.
0 commit comments