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 866136b commit 3ef46b9Copy full SHA for 3ef46b9
house-robber/iam-edwin.java
@@ -0,0 +1,13 @@
1
+class Solution {
2
+ public int rob(int[] nums) {
3
+ int[] result = new int[nums.length + 2];
4
+
5
+ for (int index = nums.length - 1; index >= 0; index--) {
6
+ int robFirst = nums[index] + result[index + 2];
7
+ int passFirst = result[index + 1];
8
+ result[index] = Integer.max(robFirst, passFirst);
9
+ }
10
11
+ return result[0];
12
13
+}
0 commit comments