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.
Tests:
Runtime:
Memory:
Test
Input:
Expected:
Got:
Click Run Code to test against sample cases, or Submit to test against all cases.
▲ Console