问题描述:

You are climbing a stair case. It takes n steps to reach to the top.

Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?

Note: Given n will be a positive integer.

Example 1:

Input: 2
Output: 2
Explanation: There are two ways to climb to the top.
1. 1 step + 1 step
2. 2 steps

Example 2:

Input: 3
Output: 3
Explanation: There are three ways to climb to the top.
1. 1 step + 1 step + 1 step
2. 1 step + 2 steps
3. 2 steps + 1 step

源码:

和剑指offer第二版77页剑指offer-跳台阶是一样的。动态规划就行了dp[i] = dp[i-1] + dp[i-2]

leetcode【70】Climbing Stairs

相关文章:

  • 2021-07-13
  • 2021-10-29
  • 2021-10-21
  • 2021-12-08
  • 2021-10-08
  • 2022-12-23
猜你喜欢
  • 2021-08-06
  • 2022-01-04
  • 2022-01-27
  • 2022-01-27
  • 2021-09-29
  • 2021-10-05
相关资源
相似解决方案