Skip to content

Commit ec729e1

Browse files
committed
feat: house robber
1 parent 0d5334c commit ec729e1

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

house-robber/minji-go.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution {
2+
public int rob(int[] nums) {
3+
int[] sum = new int[nums.length+1];
4+
sum[0] = nums[0];
5+
if(nums.length>1) sum[1] = Math.max(nums[0], nums[1]);
6+
for(int i=2; i<nums.length; i++){
7+
sum[i]=Math.max(nums[i]+sum[i-2],sum[i-1]);
8+
}
9+
return sum[nums.length-1];
10+
}
11+
}

0 commit comments

Comments
 (0)