Fibonacci Number

Easy

The Fibonacci sequence is defined by F(0) = 0, F(1) = 1 and F(n) = F(n - 1) + F(n - 2) for n > 1.

Given n, return F(n).

Example 1

fib()
Input
n = 2
Output
1

Example 2

fib()
Input
n = 4
Output
3

Why

0, 1, 1, 2, 3
Constraints
0 <= n <= 30

Topics

MathDynamic ProgrammingRecursion

Implement fib in the editor and return the answer — printing it is never graded.