程式語言 - LeetCode - C - 198. House Robber



參考資訊:
https://www.cnblogs.com/grandyang/p/4383632.html

題目:


解答:

int max(int a, int b)
{
    return a > b ? a : b;
}

int rob(int *nums, int numsSize)
{
    int cc = 0;
    int ev = 0;
    int od = 0;

    for (cc = 0; cc < numsSize; cc++) {
        if ((cc % 2) == 0) {
            ev = max(ev + nums[cc], od);
        }
        else {
            od = max(ev, od + nums[cc]);
        }
    }
    return max(ev, od);
}