← All problems

Climbing Stairs

easy

You're climbing a staircase with n steps. Each move you can climb 1 or 2 steps. Return the number of distinct ways to reach the top.

This count follows the exact recurrence in Fibonacci memoization — ways(n) = ways(n-1) + ways(n-2).

Example

Input: n = 4
Output: 5        // 1+1+1+1, 1+1+2, 1+2+1, 2+1+1, 2+2
Loading...