Posted on

Description

Submssions

Submission I(Failed)

class Solution {
public:
    int climbStairs(int n) {
        if(n == 0 || n == 1) return 1;
        return climbStairs(n - 1) + climbStairs(n - 2);
    }
};

Submission II

class Solution {
public:
    int climbStairs(int n) {
        if(n < 2) return 1;
        vector<int> dp(n+1);
        dp[0] = dp[1] = 1;
        for(int i = 2; i <= n; ++i) {
            dp[i] = dp[i-2] + dp[i-1];
        }
        return dp[n];
    }
};

Leave a Reply

Your email address will not be published. Required fields are marked *