Fibonacci Number
Medium
recursion
dynamic-programming
math
Fibonacci Number
The Fibonacci numbers are: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ...
Given n, calculate F(n).
Example 1
Input: 5
Output: 5
Explanation: F(5) = F(4) + F(3) = 3 + 2 = 5
Example 2
Input: 10
Output: 55
Constraints
- 0 ≤ n ≤ 30
Sample Test Cases
Example 1
Input:
(none)
Expected Output:
0
Example 2
Input:
1
Expected Output:
1
Example 3
Input:
5
Expected Output:
5
Keyboard shortcuts:
- • Ctrl/Cmd + Enter to submit
📈 Statistics
Submissions
0
Accepted
0