爬楼梯

时间:2017-03-08 23:11:55   收藏:0   阅读:340
class Solution {
public:
    /**
     * @param n: An integer
     * @return: An integer
     */
    int climbStairs(int n) {
        // write your code here
        if(n == 0) return 1;
   if(n <= 2) return n;
   int step_1,step_2,step_3;
   step_1 = 1;
   step_2 = 2;
   for(int i = 2; i < n; ++i)
   {
       step_3 = step_1 + step_2;
       step_1 = step_2;
       step_2 = step_3;
   }
   return step_3;
    }
};

 

原文:http://www.cnblogs.com/t-p-h/p/6523212.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!