爬楼梯

class Solution {
public:
    /**
     * @param n: An integer
     * @return: An integer
     */
    int climbStairs(int n) {
        // write your code here
        int step1=1;
        int step2=2;
        int step3=0;
        if(n<=1)
        return step1;
        if(n==2)
        return step2;
        while ((n--) - 2) {
            step3 = step1 + step2;
            step1 = step2;
            step2 = step3;
        }
        return step3;
    }
};

 

  

posted @ 2017-03-06 21:19  daifengjiao  阅读(97)  评论(0编辑  收藏  举报