Skip to content

Commit 39676c6

Browse files
Add fibonacci algorithm in maths folder
1 parent e2a78d4 commit 39676c6

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

fibonacci.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
def fibonacci(n: int) -> list[int]:
2+
"""
3+
Return first n Fibonacci numbers.
4+
Example:
5+
>>> fibonacci(5)
6+
[0, 1, 1, 2, 3]
7+
"""
8+
if n <= 0:
9+
return []
10+
fib_seq = [0, 1]
11+
for i in range(2, n):
12+
fib_seq.append(fib_seq[i-1] + fib_seq[i-2])
13+
return fib_seq[:n]

0 commit comments

Comments
 (0)