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 a63ea90 commit c033942Copy full SHA for c033942
house-robber/mintheon.java
@@ -0,0 +1,28 @@
1
+class Solution {
2
+ public int rob(int[] nums) {
3
+ int[] sums = new int[nums.length];
4
+
5
+ sums[0] = nums[0];
6
7
+ if (nums.length > 1) {
8
+ sums[1] = nums[1];
9
+ }
10
11
+ if (nums.length > 2) {
12
+ sums[2] = nums[0] + nums[2];
13
14
15
+ if (nums.length > 3) {
16
+ for (int i = 3; i < nums.length; i++) {
17
+ sums[i] = Math.max(nums[i] + sums[i - 2], nums[i] + sums[i - 3]);
18
19
20
21
+ int max = 0;
22
+ for(int sum : sums) {
23
+ max = Math.max(sum, max);
24
25
26
+ return max;
27
28
+}
0 commit comments