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 valid sequence ends with either a 1-step move from step 4 or a 2-step move from step 3, giving 5 + 3 = 8 sequences.
Constraints
1 <= n <= 45.