题目描述

一只青蛙一次可以跳上1级台阶,也可以跳上2级。求该青蛙跳上一个n级的台阶总共有多少种跳法。

【思路】与斐波那契数列类似

 1 class Solution {
 2 public:
 3     int jumpFloor(int number) {
 4         int res[100] = {0};
 5         res[0] = 1;
 6         res[1] = 2;
 7         for(int i = 2;i < number;i ++){
 8             res[i] = res[i - 1] + res[i - 2];
 9         }
10         return res[number - 1];
11     }
12 };

 

相关文章:

  • 2021-12-29
  • 2021-09-21
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-21
  • 2021-05-01
  • 2021-08-13
猜你喜欢
  • 2021-05-18
  • 2022-12-23
  • 2022-03-02
  • 2022-01-17
  • 2021-03-30
  • 2021-10-26
  • 2021-10-04
相关资源
相似解决方案