Here is a cool recursive solution to the fibonacci sequence in one line! However, runtime is O(2^n)... so iterative solution is the better route to take for performance.
int fib(int n){ return n <= 2 ? 1: fib(n-1) + fib(n-2); }
Technology, Music, & Culture Blog
Here is a cool recursive solution to the fibonacci sequence in one line! However, runtime is O(2^n)... so iterative solution is the better route to take for performance.
int fib(int n){ return n <= 2 ? 1: fib(n-1) + fib(n-2); }
0 comments:
Post a Comment