Skip to content

Commit 0b7dff6

Browse files
dohee789dohee789
authored andcommitted
👔 house-robber solution
1 parent 1620167 commit 0b7dff6

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

house-robber/dohee789.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
https://leetcode.com/problems/house-robber/
3+
*/
4+
class Solution{
5+
public int rob(int[] nums){
6+
if(nums.length == 0 || nums == null) return 0;
7+
if(nums.length == 1) return 0;
8+
9+
int prev1 = 0;
10+
int prev2 = 0;
11+
for(int num: nums){
12+
int temp = Math.max(prev1, prev2+num);
13+
prev2 = prev1;
14+
prev1 = temp;
15+
}
16+
17+
return prev1;
18+
}
19+
}
20+
21+

0 commit comments

Comments
 (0)