You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Iterative solution
def fibonacci(n):
# special case
if n == 1:
return [0]
# initialize the array
arr = [0, 1]
# and populate it, remember to skip the 2 values that are already
present
for i in range(2, n):
arr.append(arr[-1]+arr[-2])
return arr
# Recursive solution
def fibonacci(n):
# handle special cases
print(n)
if n < 2:
return [0]
if n < 3:
return [0, 1]
# normal case as n decreases from original value to 2
arr = fibonacci(n-1)
arr.append(arr[n-2] + arr[n-3])
return arr
Fibonacci
Find the sequence Sum
Maximizing Profit from Stocks
The text was updated successfully, but these errors were encountered: