Climbing Stairs
Updated
Problem statement
Given n, the number of steps in a staircase, return how many distinct sequences of moves reach exactly the top.
Each move climbs either 1 step or 2 steps.
Function
climbStairs(n: int) → intExamples
Example 1
n = 2return = 2The two valid sequences are 1 + 1 and 2.
Example 2
n = 5return = 8The last move is one step from step 4 or two steps from step 3. Add the ways to reach each of those steps: 5 + 3 = 8.
Example 3
n = 1return = 1There is one way to climb one step.
Constraints
1 <= n <= 45.