1015. Sum of Fibonacci Numbers
Given an integer n, return the sum of the first n Fibonacci numbers, starting with 0 and 1.
The Fibonacci sequence is defined as:
F(0) = 0
F(1) = 1
F(n) = F(n - 1) + F(n - 2) for n ≥ 2
You are required to return the sum F(0) + F(1) + ... + F(n).
Example 1:
Input: n = 3
Output: 4
Explanation: F(0) + F(1) + F(2) + F(3) = 0 + 1 + 1 + 2 = 4
Example 2:
Input: n = 5
Output: 12
Explanation: 0 + 1 + 1 + 2 + 3 + 5 = 12
Now Your Turn!
Pick the correct output for the given inputInput: 4
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- 0 <= n <= 50