We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 171481e commit b5c47eeCopy full SHA for b5c47ee
1 file changed
knapsack/knapsack.py
@@ -4,7 +4,7 @@
4
5
from __future__ import annotations
6
7
-from functools import lru_cache
+from functools import cache
8
9
10
def knapsack(
@@ -37,7 +37,7 @@ def knapsack(
37
got the weight of 10*5 which is the limit of the capacity.
38
"""
39
40
- @lru_cache(maxsize=None)
+ @cache
41
def knapsack_recur(capacity: int, counter: int) -> int:
42
# Base Case
43
if counter == 0 or capacity == 0:
@@ -93,7 +93,7 @@ def knapsack_with_count(
93
(2, 2)
94
95
96
97
def knapsack_recur(remaining_capacity: int, item_count: int) -> tuple[int, int]:
98
# Base Case: one empty subset yields value 0.
99
if item_count == 0 or remaining_capacity == 0:
0 commit comments