LeetCode 70 Climbing Stairs - Problem Statement

The problem

You're climbing a staircase with n steps. Each time you can climb 11 or 22 steps. How many distinct ways can you reach the top?

With n = 2:

  • Way 1: 1 step + 1 step.
  • Way 2: 2 steps.
  • Answer: 22.

With n = 3:

  • 1+1+1, 1+2, 2+1.
  • Answer: 33.

With n = 4:

  • From step 2, take 2 steps → 22 ways to reach step 2.
  • From step 3, take 1 step → 33 ways to reach step 3.
  • Total: 2+3=52 + 3 = 5.

Constraints: 1n451 \le n \le 45.