Skip to content

Instantly share code, notes, and snippets.

@amiiy
Created January 26, 2017 19:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amiiy/23383546da1d6b6f0017118b71e2f240 to your computer and use it in GitHub Desktop.
Save amiiy/23383546da1d6b6f0017118b71e2f240 to your computer and use it in GitHub Desktop.
fibonacci in dynamic programing way
#fibonacci series with dynamic programing Approach !
#better way ...
def fib(n):
l = [1,1]
if n == 0 :
return 1
elif n == 1 :
return 1
elif n == 2 :
return l
elif n>2 :
temp = 0
for i in range(n-2):
temp = l[-2] + l[-1]
l.append(temp)
return l
print(fib(1))
print(fib(2))
print(fib(3))
print(fib(12))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment