50个阶梯,你一次可以上一阶或两阶,走上去,共有多少种走法?

听说是百度题,嘎嘎

不多说,用递归方式,javascript 代码如下:

function c (left) {
   if ( 2 == left ){
        return 2;
   } else if (1 == left) {
         return 1;
   } else {
        return c(left-2) + c(left-1);
   }
}

  

posted @ 2012-03-02 09:43  jankuo  阅读(266)  评论(0编辑  收藏  举报