Climbing stairs
Standard · Write code · about 8 min
You climb a staircase of n stairs, taking 1 or 2 stairs per move. Return the number of different move sequences that reach the top. A staircase of 0 stairs has 1 way: do nothing.
Example 1
Input:
[4]
Output:
5
First move 1 stair (3 left) or 2 stairs (2 left).
Example 2
Input:
[2]
Output:
2
1 + 1 or 2.
Constraints
- 0 ≤ n ≤ 25
Learn the idea first: Recursion trees: Fibonacci and repeated work, a visual lesson.
More Recursion trees: Fibonacci and repeated work problems
- Calls in fib(5) Warm-up
- Fibonacci, the naive way Warm-up
- Order of calls Standard
- Repeated subproblems Standard
- Count the calls of fib Standard
- Count leaves of the call tree Challenge