(nums []int)
| 3 | import "math" |
| 4 | |
| 5 | func rob(nums []int) int { |
| 6 | if len(nums) == 0 { |
| 7 | return 0 |
| 8 | } |
| 9 | if len(nums) == 1 { |
| 10 | return nums[0] |
| 11 | } |
| 12 | |
| 13 | // The max is the max between robbing houses |
| 14 | // where the beginning and end do not connect |
| 15 | // into the ring of houses. So, that means house |
| 16 | // 0 to one from the end, and house 1 to the end. |
| 17 | return int(math.Max( |
| 18 | float64(robInRange(nums[0:len(nums)-1])), |
| 19 | float64(robInRange(nums[1:])))) |
| 20 | } |
| 21 | |
| 22 | func robInRange(nums []int) int { |
| 23 | dp := make([]int, len(nums)+1) |