Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions recursion-nth-fibonacci.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

# O(n) time | O(1) space
def getNthFib(n):
defaultArray = [0,1]

if n == 1:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move this if-block before count init since there is no need for count assignment and further while check. correct me if I am wrong

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DOne

return defaultArray[0]
else:
count = 3
while count <= n:
sum = defaultArray[0] + defaultArray[1]
defaultArray[0] = defaultArray[1]
defaultArray[1] = sum
count = count + 1
return defaultArray[1]