Skip to content

Commit 070bec9

Browse files
authored
Update and rename Easy/House Robber.java to Medium/House Robber.java
1 parent ee812ba commit 070bec9

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

Easy/House Robber.java

Lines changed: 0 additions & 14 deletions
This file was deleted.

Medium/House Robber.java

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

0 commit comments

Comments
 (0)