EasyMathDynamic ProgrammingMemoization

1 approach, code in every language

Problem description

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

After the pattern

Now solve one you haven't seen.

Rung Ladder Climbs is our own problem on the technique behind Climbing Stairs: a new statement, so there's no answer to remember. Write it in your browser and run it against graded tests.

1,194 problems · 15,062 graded tests · free