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

跳台阶扩展问题

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

--通过01组合的方式求解--<java解法>

/**
     * 一共有n个台阶,青蛙在每个台阶上都可以选择停留还是跳过,可以用0和1表示
     * 第n个台阶(最后一个台阶)的状态一定是1,所以一共有f(n)=2^(n-1)的跳法
     * 
     * 例如 000001,111111,001001
     *
     * @param target
     * @return
     */
    public static int jumpFloorII(int target) {
        if (target <= 2) {
            return target;
        }
        return  (int) Math.pow(2,target-1);
    }
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务