Skip to content

Practice Fibonacci Number

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#509
LeetCode Problem

Fibonacci Number

Problem Statement

Compute F(n), where F(0) = 0, F(1) = 1, and F(n) = F(n - 1) + F(n - 2) for n greater than 1. Return the value for the given nonnegative integer n.

Source: Fibonacci Number on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
n = 2
Output
1

# Example 2

Input
n = 3
Output
2

# Example 3

Input
n = 4
Output
3

Constraints

0 <= n <= 30

Related LeetCode Problems

Practice more problems similar to Fibonacci Number.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.