We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 20e100a commit e74483bCopy full SHA for e74483b
solution/0213.House Robber II/Solution.go
@@ -0,0 +1,26 @@
1
+func rob(nums []int) int {
2
+ l := len(nums)
3
+ if l == 0 {
4
+ return 0
5
+ }
6
+ if l == 1 {
7
+ return nums[0]
8
9
+ res1 := _rob(nums[:l-1])
10
+ res2 := _rob(nums[1:])
11
+ if res1 < res2 {
12
+ return res2
13
14
+ return res1
15
+}
16
+
17
+func _rob(nums []int) int {
18
+ x, y := 0, 0
19
+ for _, n := range nums {
20
+ x, y = y, x+n
21
+ if x > y {
22
+ y = x
23
24
25
+ return y
26
0 commit comments