s4553711
5/31/2017 - 3:45 PM

198.cpp

class Solution {
public:
    int rob(vector<int>& nums) {
        int b1 = 0, b2 = 0;
        for(int i = 0; i < nums.size(); i++) {
            int tmp = b2 + nums[i];
            b2 = b1;
            b1 = max(b1, tmp);
        }
        return max(b2, b1);
    }
};