Update
This commit is contained in:
parent
124b9d1e7c
commit
3f374a4713
85 changed files with 2281 additions and 2272 deletions
|
@ -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).
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue