Climbing Stairs

You are climbing a stair case. It takes n steps to reach to the top.code

Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?it

/**
 * @param {number} n
 * @return {number}
 */

var climbStairs=function(n){
    if(n<4) return n;
    var a=2,b=3,c=5;
    for(var i=5;i<=n;i++){
        a=c;
        c=b+c;
        b=a;
    }
    return c;
};
相關文章
相關標籤/搜索