Calculate the fibonacci number at position n recursively
(n: int)
| 19 | |
| 20 | |
| 21 | def getFibonacciRecursive(n: int) -> int: |
| 22 | """ |
| 23 | Calculate the fibonacci number at position n recursively |
| 24 | """ |
| 25 | |
| 26 | a = 0 |
| 27 | b = 1 |
| 28 | |
| 29 | def step(n: int) -> int: |
| 30 | nonlocal a, b |
| 31 | if n <= 0: |
| 32 | return a |
| 33 | a, b = b, a + b |
| 34 | return step(n - 1) |
| 35 | |
| 36 | return step(n) |
| 37 | |
| 38 | |
| 39 | def getFibonacciDynamic(n: int, fib: list) -> int: |
no test coverage detected