码迷,mamicode.com
首页 > 其他好文 > 详细

爬楼梯

时间:2017-03-08 21:16:12      阅读:116      评论:0      收藏:0      [点我收藏+]

标签:int   write   bsp   class   楼梯   public   code   param   for   

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;     } };   

爬楼梯

标签:int   write   bsp   class   楼梯   public   code   param   for   

原文地址:http://www.cnblogs.com/shanyunpeng/p/6522919.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!