From bce645eb9eb32fe04ff150147fc5f8dfa66ac26b Mon Sep 17 00:00:00 2001
From: marina <138340846+bt3gl-cryptographer@users.noreply.github.com>
Date: Mon, 7 Aug 2023 16:55:23 -0700
Subject: [PATCH] Update README.md
---
dynamic_programming/README.md | 21 ++++++++++++---------
1 file changed, 12 insertions(+), 9 deletions(-)
diff --git a/dynamic_programming/README.md b/dynamic_programming/README.md
index b6bce42..1fee5ba 100644
--- a/dynamic_programming/README.md
+++ b/dynamic_programming/README.md
@@ -79,14 +79,18 @@ function answerToProblem(input)
```python
-cache = {1: 1, 0: 1}
-
-def climbing_stairs(n) -> int:
-
- if n not in cache:
- cache[n] = climbing_stairs(n-1) + climbing_stairs(n-2)
-
- return cache[n]
+def climb_stairs_memoization(n: int) -> int:
+
+ memo = {}
+
+ def helper(n: int, memo: dict[int, int]) -> int:
+ if n == 0 or n == 1:
+ return 1
+ if n not in memo:
+ memo[n] = helper(n-1, memo) + helper(n-2, memo)
+ return memo[n]
+
+ return helper(n, memo)
```
@@ -178,4 +182,3 @@ def backtrack(candidate):
remove(next_candidate)
````
-