We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 1620167 commit 0b7dff6Copy full SHA for 0b7dff6
house-robber/dohee789.java
@@ -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