题解 | #跳台阶#

跳台阶

http://www.nowcoder.com/practice/8c82a5b80378478f9484d87d1c5f12a4

递归方法,可优化。

public class Solution {
    public int jumpFloor(int target) {

        int res=0;
        if(target==1){
            return 1;
        }
        if(target==2){
            return 2;
        }
        if(target>2){
            return jumpFloor(target-1)+jumpFloor(target-2);
        }
        return 0;
    }
}

动态该规划的思路也挺好的。

全部评论

相关推荐

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