leetcode-打家劫舍模板
打家劫舍模板:
function rob($nums) {
$first = $nums[0];
$second = max($nums[1], $nums[0]);
for ($i = 2; $i < count($nums); $i++) {
$tmp = $second;
$second = max($first + $nums[$i], $second);
$first = $tmp;
}
return $second;
}
本文来自博客园,作者:吴丹阳-V,转载请注明原文链接:https://www.cnblogs.com/wudanyang/p/15778803.html