class Solution {
public:
int rob(vector<int>& nums) {
if (nums.size() <= 1)
{
return nums.size() == 0 ? 0 : nums[0];
}
int lastTime = 0, secondLastTime = 0;
for (int l = 0; l < nums.size(); l++)
{
int recordLastTime = lastTime, recordSecondLastTime = secondLastTime;
secondLastTime = recordLastTime + nums[l];
lastTime = max(recordLastTime, recordSecondLastTime);
}
return max(lastTime, secondLastTime);
}
};