Commit 1989b6bb authored by Martin Mareš's avatar Martin Mareš
Browse files

Rekurze: Ještě Fibonacci v konstantní paměti

parent 64f1e21f
......@@ -26,3 +26,13 @@ def fib2(n):
for i in range(2, n+1):
p[i] = p[i-1] + p[i-2]
return p[n]
### Iterativní řešení s konstantní pamětí
def fib3(n):
if n < 2:
return n
a, b = 0, 1
for i in range(1, n):
a, b = b, a+b
return b
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment