EasyMathDynamic ProgrammingMemoization

Climbing Stairs

LeetCode
1 approach, code in all languages

You are climbing a staircase that has n steps to reach the top. On each move you may advance either one step or two steps.

Return the total number of distinct sequences of moves that take you from the ground to the very top of the staircase.

Example 1

Input: n = 2

Output: 2

There are two ways: take a single step twice (1 + 1), or take one double step (2).

Example 2

Input: n = 3

Output: 3

The three orderings are 1 + 1 + 1, 1 + 2, and 2 + 1.

Constraints

  • 1 <= n <= 45
You've got the patterns

Patterns get you through the screen. Shipping gets you hired.

FDE Coach is a cohort-based program in frontend, backend, AWS, and AI where you build real products and get referred to 200+ hiring partners. The free live workshop is the fastest way to see how we teach.

750+ engineers trained · frontend, backend, AWS & AI

August 15 · 0d left
Enroll Now