Easy
💻 Coding
[JavaScript Master] Climbing Stairs DP
Problem Statement
Problem Statement for Climbing Stairs DP under JavaScript Master:
You are climbing a staircase. It takes n steps to reach the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?
Input Constraints:
- 1 <= len(nums) <= 10^5
- Elements fit in memory standard spaces.
Proposed Solution
def climbStairs(n):
if n <= 2:
return n
dp = [0] * (n + 1)
dp[1] = 1
dp[2] = 2
for i in range(3, n + 1):
dp[i] = dp[i-1] + dp[i-2]
return dp[n]
Your Progress
Pending Completion
Save Progress?
Login to sync your solutions across all dynamic local and remote sessions.
Join Techlance