Climbing Stairs

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

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

/**
 * @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;
};

posted @ 2015-10-02 23:00  chaha  阅读(112)  评论(0编辑  收藏  举报