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 d606f26 commit 161c76bCopy full SHA for 161c76b
house-robber/samcho0608.java
@@ -1,11 +1,15 @@
1
class Solution {
2
+ // Problem:
3
// * can't rob two adj houses in the same night
4
// * return: max amount of money robbale in one night
5
+ // Solution:
6
+ // * Time Complexity: O(N)
7
+ // * Space Complexity: O(N)
8
public int rob(int[] nums) {
9
if(nums.length == 1) return nums[0];
10
if(nums.length == 2) return Math.max(nums[0], nums[1]);
11
- // maxSum[i] = max sum possible at i (inclusive)
12
+ // maxSum[i] = max sum possible with nums[i]
13
int[] maxSum = new int[nums.length];
14
maxSum[0] = nums[0];
15
maxSum[1] = nums[1];
0 commit comments