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>
|
<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)
|
||||||
````
|
````
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user