LeetCode 509. Fibonacci Number — Using Recursion in JavaScript

This week has not been any different than the past few weeks as I have been studying more and more to be better prepared for upcoming interviews. This week the problem I decided to spotlight is another easy problem from LeetCode. Problem 509 is titled Fibonacci Number.

The Problem:

F(0) = 0,   F(1) = 1
F(N) = F(N - 1) + F(N - 2), for N > 1.

Given N, calculate F(N

My Solution:

let fib = function(N) {
if (N <= 0) {
return 0;
} else if (N === 1) {
return 1;
} else {
return fib(N-1) + fib(N-2)
}
};

Runtime: 112 ms

Memory Usage: 38.3 MB