We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 134e683 commit 95027fbCopy full SHA for 95027fb
Sprint-2/improve_with_caches/fibonacci/fibonacci.py
@@ -1,4 +1,8 @@
1
-def fibonacci(n):
+def fibonacci(n, memo={}):
2
+ if n in memo:
3
+ return memo[n]
4
if n <= 1:
5
return n
- return fibonacci(n - 1) + fibonacci(n - 2)
6
+
7
+ memo[n] = fibonacci(n - 1, memo) + fibonacci(n - 2, memo)
8
0 commit comments