[leetcode]Climbing Stairs

class Solution {

public:

    int climbStairs(int n) {

        // Start typing your C/C++ solution below

        // DO NOT write int main() function

        if(n <= 2) return n;

        

        vector<int> f(n+1, 0);

        f[1] = 1;

        f[2] = 2;

        

        for(int i = 3; i <= n; i++){

            f[i] = f[i-1]+f[i-2];

        }

        

        return f[n];

        

    }

};


你可能感兴趣的:(LeetCode)