```
public class Solution {
public int rob(int[] nums) {
return robHelper(nums, 0);
}
Map<Integer, Integer> map = new HashMap<Integer, Integer>();
private int robHelper(int[] nums, int i) {
if (i >= nums.length)
return 0;
if (map.containsKey(i))
return map.get(i);
else {
int max = Math.max(nums[i] + robHelper(nums, i + 2),
robHelper(nums, i + 1));
map.put(i, max);
return max;
}
}
}
```