题目:
题解:
func _rob(nums []int) int {first, second := nums[0], max(nums[0], nums[1])for _, v := range nums[2:] {first, second = second, max(first+v, second)}return second
}func rob(nums []int) int {n := len(nums)if n == 1 {return nums[0]}if n == 2 {return max(nums[0], nums[1])}return max(_rob(nums[:n-1]), _rob(nums[1:]))
}func max(a, b int) int {if a > b {return a}return b
}