```
public class Solution {
public int rob(int[] nums) {
return Math.max(rob(nums, 0, nums.length-2), rob(nums, 1, nums.length-1));
}
public int rob(int[] nums, int lo, int hi) {
int preRob = 0, preNotRob = 0, rob = 0, notRob = 0;
for (int i = lo; i <= hi; i++) {
rob = preNotRob + nums[i];
notRob = Math.max(preRob, preNotRob);
preNotRob = notRob;
preRob = rob;
}
return Math.max(rob, notRob);
}
```

}