【LeetCode】70. Climbing Stairs

来源:互联网 发布:生成对抗网络最新 编辑:程序博客网 时间:2024/04/28 10:47

Problem here

Problem

You are climbing a stair case. It takes n steps to reach to the top.

Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?

Solution

這題之前做過
就是超級樓梯那條

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