Skip to content

Commit 9abc593

Browse files
authored
Create fibonacci_series.py
Added Fibonacci series with Dynamic Approach
1 parent a132e47 commit 9abc593

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
def fibonacci(n: int) -> list:
2+
"""Return a list containing the first n Fibonacci numbers."""
3+
if n <= 0:
4+
return []
5+
if n == 1:
6+
return [0]
7+
fib = [0, 1]
8+
for _ in range(2, n):
9+
fib.append(fib[-1] + fib[-2])
10+
return fib
11+
12+
13+
# Example usage
14+
print(fibonacci(10))
15+
print(fibonacci(20))

0 commit comments

Comments
 (0)