Climbing Stairs
Problem statement
You are climbing a staircase with n steps.
On each move, you may climb either 1 step or 2 steps. Return the number of distinct sequences of moves that reach exactly the top.
Function
climbStairs(n: int) → intExamples
Example 1
n = 2return = 2The two valid sequences are 1 + 1 and 2.
Example 2
n = 5return = 8Every sequence ends with a one-step move from step 4 or a two-step move from step 3, giving 5 + 3 = 8.
Example 3
n = 1return = 1There is one way to climb one step.
Constraints
1 <= n <= 45.