clueless coding // TODO: be smarter

LeetCode House Robber: CPP Solution



TL;DR Code Solution


int rob(vector<int>& nums) {

    int prevYes = 0;
    int prevNo = 0;

    for (int i = 0; i < nums.size(); i++) {
        int temp = prevYes;
        prevYes = max(prevNo, prevYes);
        prevNo = nums[i] + temp;
    }

    return max(prevYes, prevNo);

}