首页 > 其他 > 详细

leetcode 198 House Robber I

时间:2020-01-14 14:22:49      阅读:61      评论:0      收藏:0      [点我收藏+]
function rob(nums) {
    if(!nums || nums.length === 0) {
        return 0;
    } else if(nums.length < 2){
        return nums[0];
    }
    let memo = new Array(nums.length);
    memo[0] = nums[0];
    memo[1] = Math.max(nums[0], nums[1]);
    for(let i = 2; i < nums.length; i++) {
        memo[i] = Math.max(memo[i-2]+nums[i], memo[i-1]);
    }
    return memo[memo.length-1];
}

leetcode 198 House Robber I

原文:https://www.cnblogs.com/rubylouvre/p/12191387.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!