Skip to content

Commit dcd9377

Browse files
committed
solve house robber problem
1 parent 615e84a commit dcd9377

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

house-robber/sora0319.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
11
import java.util.*;
2+
// 2번째 풀이
3+
class Solution {
4+
public int rob(int[] nums) {
5+
int[] dp = new int[nums.length+1];
6+
dp[1] = nums[0];
7+
8+
for(int i = 1; i < nums.length; i++){
9+
dp[i+1] = Math.max(dp[i-1] + nums[i], dp[i]);
10+
}
11+
return dp[nums.length];
12+
}
13+
}
14+
15+
16+
17+
// 1번째 풀이
218
class Solution {
319
public int rob(int[] nums) {
420
int[] house = new int[nums.length];

0 commit comments

Comments
 (0)