leetcode 70. 爬楼梯

 

 

思路

动态规划 斐波拉契呀数列

代码

class Solution {
public:
    int climbStairs(int n) {
        vector<int>res_dp(n+5,0);
        res_dp[1] = 1;
        res_dp[2] = 2;
        for(int i = 3;i<=n;i++)
        {
            res_dp[i] = res_dp[i-1]+res_dp[i-2]; //斐波拉奇亚数列
        }
        return res_dp[n];

    }
};

 

posted @ 2021-09-26 15:56  A-inspire  Views(18)  Comments(0Edit  收藏  举报