标签:UNC max array use script else turn leetcode etc
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];
}
标签:UNC max array use script else turn leetcode etc
原文地址:https://www.cnblogs.com/rubylouvre/p/12191387.html