Created
July 22, 2019 12:14
-
-
Save raheemazeezabiodun/dcde041c3f23f92dc55004562d54e0f1 to your computer and use it in GitHub Desktop.
A fibonacci sequence with a better approach
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def slow_fibonacci_number(n): | |
if n <= 1: | |
return n | |
return slow_fibonacci_number(n - 1) + slow_fibonacci_number(n - 2) | |
def fast_fibonacci_number(n): | |
numbers = [0, 1] | |
for num in range(2, n+1): | |
numbers.append(numbers[num - 1] + numbers[num - 2]) | |
return numbers[n] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment