Skip to content

Commit 9aeb68c

Browse files
authored
Merge pull request #2 from sriramanvellingiri/nth-fib
2 parents 9ae429e + 9b0940f commit 9aeb68c

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

recursion-nth-fibonacci.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
# O(n) time | O(1) space
3+
def getNthFib(n):
4+
defaultArray = [0,1]
5+
6+
if n == 1:
7+
return defaultArray[0]
8+
9+
count = 3
10+
while count <= n:
11+
sum = defaultArray[0] + defaultArray[1]
12+
defaultArray[0] = defaultArray[1]
13+
defaultArray[1] = sum
14+
count = count + 1
15+
return defaultArray[1]

0 commit comments

Comments
 (0)