```
public class Solution {
public int rob(int[] nums) {
//corner case
if(nums.length==0) {
return 0;
}
else if(nums.length == 1) {
return nums[0];
}
//dynamic programming
int first = 0;
int second = nums[0];
for(int i = 1; i < nums.length; i++) {
if(nums[i]+first >= second) {
int tmp = second;
second = nums[i]+first;
first = tmp;
}
else{
first = second;
}
}
return second;
}
}
```