动态回归Leetcode 70 Climbing Stairs

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/shey666/article/details/80849381

Leetcode 70

Climbing Stairs

class Solution {
public:
    int climbStairs(int n) {
        if (n <= 2) return n;
        int p = 1, q = 2;
        for (int i = 2; i < n; i++) {
            int t = p+q;
            p = q;
            q = t;
        }
        return q;
    }
};

猜你喜欢

转载自blog.csdn.net/shey666/article/details/80849381