MCPcopy Create free account
hub / github.com/austingebauer/go-leetcode / rob

Function rob

house_robber_ii_213/solution.go:5–20  ·  view source on GitHub ↗
(nums []int)

Source from the content-addressed store, hash-verified

3import "math"
4
5func 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
22func robInRange(nums []int) int {
23 dp := make([]int, len(nums)+1)

Callers 1

Test_robFunction · 0.70

Calls 1

robInRangeFunction · 0.85

Tested by 1

Test_robFunction · 0.56