Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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)

AltStyle によって変換されたページ (->オリジナル) /