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 0d5334c commit ec729e1Copy full SHA for ec729e1
house-robber/minji-go.java
@@ -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