ntree.ai
ntree.aiClimbing Stairs

Climbing Stairs

easysolvedattempted

You are given an integer n, the number of steps in a staircase. Each time you can climb either 1 or 2 steps.

Return the number of distinct ways to climb to the top.

Example 1:

Input:  n = 5
Output: 8
Explanation: 1+1+1+1+1, 1+1+1+2, 1+1+2+1, 1+2+1+1, 2+1+1+1, 1+2+2, 2+1+2 and 2+2+1.

Example 2:

Input:  n = 2
Output: 2
Explanation: 1+1 and 2.

Constraints:

  • 1 <= n <= 40
def climbStairs(n: int) -> int:
pass
 

Press Visualise to step through your code.