funcRob1(nums []int)int{var dp =make([]int,0)iflen(nums)==0{return0}iflen(nums)==1{return nums[0]}
dp =append(dp,0)
dp =append(dp, nums[0])for i :=2; i <=len(nums); i++{
dp =append(dp,MyMax(dp[i -2]+ nums[i -1], dp[i -1]))}return dp[len(nums)]}funcMyMax(a, b int)int{if a >= b{return a
}else{return b
}}// 优化一下 降低空间复杂度funcRob2(nums []int)int{iflen(nums)==0{return0}iflen(nums)==1{return nums[0]}
pre :=0
cur := nums[0]for i :=2; i <=len(nums); i++{
tmpCur := cur
cur=MyMax(pre + nums[i -1], cur)
pre = tmpCur
}return cur
}