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 bb8d394 commit e0383fbCopy full SHA for e0383fb
1 file changed
house-robber/youngDaLee.go
@@ -0,0 +1,27 @@
1
+package youngDaLee
2
+
3
+func rob(nums []int) int {
4
+ if len(nums) == 0 {
5
+ return 0
6
+ }
7
+ if len(nums) == 1 {
8
+ return nums[0]
9
10
11
+ dp := make([]int, len(nums))
12
+ dp[0] = nums[0]
13
+ dp[1] = max(nums[0], nums[1])
14
15
+ for i := 2; i < len(nums); i++ {
16
+ dp[i] = max(dp[i-1], dp[i-2]+nums[i])
17
18
19
+ return dp[len(nums)-1]
20
+}
21
22
+func max(a, b int) int {
23
+ if a > b {
24
+ return a
25
26
+ return b
27
0 commit comments