题解 | #跳台阶#

跳台阶

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

动态规划 滚动数组减少空间复杂度
public class Solution {
    public int jumpFloor(int target) {
        if(target<=2)
            return target;
        int dp0=1;
        int dp1=2;
        int temp=0;   //滚动数组
        for(int i=3;i<=target;i++){
            temp=dp1;
            dp1=dp1+dp0;
            dp0=temp;
        }
        return dp1;

    }
}

全部评论

相关推荐

12-13 14:51
已编辑
井冈山大学 算法工程师
龙虾x:算法比你强的没有你美,比你美的…..算了已经没有比你美的了
工作两年想退休了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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