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 a9510f8 commit 485e993Copy full SHA for 485e993
198. House Robber.java
@@ -0,0 +1,13 @@
1
+public class Solution {
2
+ public int rob(int[] nums) {
3
+ if (nums.length == 0) return 0;
4
+ else if (nums.length == 1) return nums[0];
5
+ else {
6
+ nums[1] = Math.max(nums[0], nums[1]);
7
+ for (int i = 2; i < nums.length; i++) {
8
+ nums[i] = Math.max(nums[i-1], nums[i-2] + nums[i]);
9
+ }
10
+ return nums[nums.length-1];
11
12
13
+}
0 commit comments