Climbing Stairs

You are climbing a staircase with n steps. Each time you can climb either 1 step or 2 steps.

Return the number of distinct ways you can climb to the top.

Example 1
Inputn = 2
Output2
There are two ways to climb to the top: 1 step + 1 step, or 2 steps.
Example 2
Inputn = 3
Output3
There are three ways to climb to the top: 1 + 1 + 1, 1 + 2, or 2 + 1.

Constraints

  • 1 <= n <= 45

Asked at 38 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate