Update README.md

This commit is contained in:
marina 2023-08-07 16:55:23 -07:00 committed by GitHub
parent 6b3923e32c
commit bce645eb9e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -79,14 +79,18 @@ function answerToProblem(input)
<br> <br>
```python ```python
cache = {1: 1, 0: 1} def climb_stairs_memoization(n: int) -> int:
def climbing_stairs(n) -> int: memo = {}
if n not in cache: def helper(n: int, memo: dict[int, int]) -> int:
cache[n] = climbing_stairs(n-1) + climbing_stairs(n-2) if n == 0 or n == 1:
return 1
return cache[n] if n not in memo:
memo[n] = helper(n-1, memo) + helper(n-2, memo)
return memo[n]
return helper(n, memo)
``` ```
<br> <br>
@ -178,4 +182,3 @@ def backtrack(candidate):
remove(next_candidate) remove(next_candidate)
```` ````