Climbing Stairs
Easy
Recursion
Math
Dynamic Programming
You can climb 1 or 2 steps at a time. How many distinct ways to reach step n?
Constraints
1 ≤ n ≤ 45
Examples
Example 1:
Input: 2
Output: 2
Explanation: 1+1 or 2
Example 2:
Input: 3
Output: 3
Explanation: 1+1+1, 1+2, 2+1
Hints
dp[n] = dp[n-1] + dp[n-2]. It's Fibonacci!
Tests:
Runtime:
Memory:
Test
Input:
Expected:
Got:
Click Run Code to test against sample cases, or Submit to test against all cases.
▲ Console