Fibonacci Number

Easy
Recursion Math Dynamic Programming Recursion

Given n, return the nth Fibonacci number. F(0)=0, F(1)=1, F(n)=F(n-1)+F(n-2).

Constraints

0 ≤ n ≤ 30

Examples

Example 1:
Input: 0
Output: 0
Example 2:
Input: 1
Output: 1

Hints

Use iteration or memoization to avoid exponential time.
▲ Console

Install Talent Arabia

Get instant access to jobs and career tools on your device.