Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fibonacci recursion #8

Open
ac812 opened this issue Nov 2, 2022 · 1 comment
Open

Fibonacci recursion #8

ac812 opened this issue Nov 2, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@ac812
Copy link
Owner

ac812 commented Nov 2, 2022

re write exercise Fibonacci recursion in Practical 4 so that it only returns the ith Element of the Sequence not the full sequence - O2 complexity

@ac812 ac812 added the enhancement New feature or request label Nov 2, 2022
@ac812
Copy link
Owner Author

ac812 commented Nov 2, 2022

possible other option:
def fibonacci(n):
if n==0:
return 0
if n==1:
return [1]
if n == 2:
return [1,1]
else:
prev = fibonacci (n-1)
return prev + [prev[-1]+prev[-2]]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant