*Click on the image to read the comments*

```
public int rob (int [] nums) {
if (nums == null){return -1;}
if (nums.length == 0){ return 0;}
if (nums.length == 1) {return nums[0];}
int [] weight = new int [nums.length];
for (int i =0; i <nums.length;i++){
weight [i] = nums[i] + weightCompute (weight,i);
}
if (weight [ nums.length-1] > weight [ nums.length-2] ){
return weight [ nums.length-1];
}
return weight [ nums.length-2] ;
}
public int weightCompute (int nums [], int id ){
int i = id -2;
if (i <0){
return 0;
}
int max = -1;
for (; i>=0; i--){
if (max < nums[i]){
max = nums[i];
}
}
return max;
}
```