This commit is contained in:
Miloslav Ciz 2024-08-31 14:44:45 +02:00
parent 124b9d1e7c
commit 3f374a4713
85 changed files with 2281 additions and 2272 deletions

View file

@ -28,18 +28,18 @@ int fib(int n)
{
if (n < 2)
return n;
int current = 1, prev = 0;
for (int i = 2; i <= n; ++i)
{
int tmp = current;
current += prev;
prev = tmp;
}
return current;
}
```
Now the code is longer, but it is faster. In this specific case we only need to remember the previously computed Fibonacci number (in practice we may need much more memory for remembering the partial results).
Now the code is longer, but it is faster. In this specific case we only need to remember the previously computed Fibonacci number (in practice we may need much more memory for remembering the partial results).