Climbing Stairs
You may climb either one or two steps at a time. Return the number of distinct step sequences that reach exactly n steps.
Example 1
n = 58Explanation
For five steps, counts with zero, one or two two-step moves are 1,4,3, totaling 8.
Example 2
n = 1089Explanation
ways(n)=ways(n-1)+ways(n-2) gives 89 for ten steps; move order matters.
Example 3
n = 11Explanation
One step can only be reached with a single one-step move.
Constraints
- 1 <= n <= 45
Function contract
climbStairsArguments: jsonSolutionRuns on your device
Loading draft…
Run: 3 examples; Submit: 32 cases, on your device.
5