mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-04-29 20:26:07 -04:00
Update README.md
This commit is contained in:
parent
6b3923e32c
commit
bce645eb9e
@ -79,14 +79,18 @@ function answerToProblem(input)
|
||||
<br>
|
||||
|
||||
```python
|
||||
cache = {1: 1, 0: 1}
|
||||
def climb_stairs_memoization(n: int) -> int:
|
||||
|
||||
def climbing_stairs(n) -> int:
|
||||
memo = {}
|
||||
|
||||
if n not in cache:
|
||||
cache[n] = climbing_stairs(n-1) + climbing_stairs(n-2)
|
||||
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 cache[n]
|
||||
return helper(n, memo)
|
||||
```
|
||||
|
||||
<br>
|
||||
@ -178,4 +182,3 @@ def backtrack(candidate):
|
||||
remove(next_candidate)
|
||||
````
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user