斐波那契数列;

 1 class Solution {
 2 public:
 3     int climbStairs(int n) {
 4         // Start typing your C/C++ solution below
 5         // DO NOT write int main() function
 6         if (n <= 0) {
 7             return 0;
 8         }
 9         vector<int> fb(n + 1, 1);
10         fb[2] = 2;
11         for (int i = 3; i <= n; ++i) {
12             fb[i] = fb[i - 1] + fb[i - 2];
13         }
14         return fb[n];
15     }
16 };

 

相关文章:

  • 2022-01-23
  • 2022-02-03
  • 2021-08-12
  • 2021-12-01
  • 2021-05-30
  • 2022-12-23
猜你喜欢
  • 2021-05-16
  • 2021-11-06
  • 2021-10-25
  • 2021-09-06
  • 2021-12-19
相关资源
相似解决方案