Open pwstrick opened 4 years ago
198. 打家劫舍
/** * @param {number[]} nums * @return {number} */ var rob = function(nums) { let dp = []; if(nums.length == 0) return 0; if(nums.length == 1) return nums[0]; if(nums.length == 2) return Math.max(nums[0], nums[1]); dp.push(nums[0]); dp.push(Math.max(nums[0], nums[1])); for(let i=2, len=nums.length; i<len; i++) { dp[i] = Math.max(dp[i-1], dp[i-2] + nums[i]); } return dp[dp.length - 1]; };
感觉你们大前端真心好啊👍
198. 打家劫舍