class Solution {
public:
int robDo(vector[HTML_REMOVED]& nums, int a, int b) {
int result;
int first = nums[a]; int second = max(nums[a], nums[a+1]);
for (int i = a+2; i <= b; i++) {
int temp = second;
second = max(first + nums[i], second);
first = temp;
}
return second;
}
int rob(vector<int>& nums) {
int length = nums.size();
if (length == 1) return nums[0];
else if (length == 2) {
return max(nums[0], nums[1]);
}
return max(robDo(nums, 0, length - 2), robDo(nums, 1, length - 1));
}
};