Fibonacci Number
Easy
Dynamic Programming
Math
Iteration
The Fibonacci numbers, commonly denoted F(n) form a sequence, called the Fibonacci sequence, such that each number is the sum of the two preceding ones, starting from 0 and 1. Given n, calculate F(n).
Examples:
Input:
2Output:
1Explanation: F(2) = F(1) + F(0) = 1 + 0 = 1.
Input:
3Output:
2Explanation: F(3) = F(2) + F(1) = 1 + 1 = 2.
Input:
4Output:
3Explanation: F(4) = F(3) + F(2) = 2 + 1 = 3.
Constraints:
- 0 ≤ n ≤ 30
Code Editor
Loading advanced editor...
Console Output
Ready to execute
Click "Run Code" to see your output here