Skip to content

Commit 73c918e

Browse files
committed
increased the speed and cut the irrelevant calls to function
1 parent b9913e3 commit 73c918e

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

fibonacci/python/Fibonacci-with-Memoization.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
# Array for saving calculated ones
7-
fib_mem = [0 for i in range(100000)]
7+
fib_mem = [0]*100000
88
fib_mem[0] = 0
99
fib_mem[1] = 1
1010

@@ -29,10 +29,13 @@ def main():
2929

3030
# Take input
3131
n = int(input("Enter the number of terms: \n"))
32+
33+
# setting the values of array
34+
temp = fibonacci(n)
3235

3336
# loop an print the series
3437
for i in range(n):
35-
print(fibonacci(i))
38+
print(fib_mem[i])
3639

3740
# Run the script
3841
main()

0 commit comments

Comments
 (0)