csc-python-solutions/18/2 - Fast Fibbonacci.py

6 lines
213 B
Python
Raw Normal View History

2021-02-17 13:23:08 +00:00
def Fibonacci(n):
sequence = [0, 1, 1] # Fibonacci(0) is 0, Fibonacci(1) and Fibonacci(2) are 1
for i in range(3, n+1):
sequence.append(sequence[i-1] + sequence[i-2])
return sequence[n]