Skip to content

Commit 3ef46b9

Browse files
committed
house robber
1 parent 866136b commit 3ef46b9

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

house-robber/iam-edwin.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)