Skip to content

Commit 3a791e1

Browse files
huaxu1024ashmichheda
authored andcommitted
Add Solution2.java for 0198.House Robber (doocs#225)
Merged doocs#225
1 parent 58da3fc commit 3a791e1

File tree

1 file changed

+9
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)