题解 | #跳台阶扩展问题#

跳台阶扩展问题

http://www.nowcoder.com/practice/22243d016f6b47f2a6928b4313c85387

```function jumpFloorII(number)
{
    // write code here
//     f(n-1) = f(0) + f(1)+f(2)+f(3) + ... + f((n-1)-1) = f(0) + f(1) + f(2) + f(3) + ... + f(n-2)
//     f(n) = f(0) + f(1) + f(2) + f(3) + ... + f(n-2) + f(n-1) = f(n-1) + f(n-1)
//     f(n) = 2*f(n-1)
    if(number===0){return 1} //其实实际执行用不到这一行
    if(number===1){return 1}
    if(number===2){return 2}
    return 2*jumpFloorII(number-1)
    
}
module.exports = {
    jumpFloorII : jumpFloorII
};
全部评论

相关推荐

1 收藏 评论
分享
牛客网
牛客企业服务