1. 程式人生 > >LintCode 111. 爬樓梯

LintCode 111. 爬樓梯

爬樓梯 bst ntc color class str ane ger 不同

假設你正在爬樓梯,需要n步你才能到達頂部。但每次你只能爬一步或者兩步,你能有多少種不同的方法爬到樓頂部?

樣例

比如n=3,1+1+1=1+2=2+1=3,共有3種不同的方法

返回 3

class Solution {
public:
    /**
     * @param n: An integer
     * @return: An integer
     */
    int a[999999];
    int climbStairs(int n) {
        // write your code here
        if(n==0)
            return
0; a[0]=1; a[1]=1; for(int i=2;i<=n;i++){ a[i]=a[i-1]+a[i-2]; } return a[n]; } };

LintCode 111. 爬樓梯