simple C solution


  • 0
    W
    int rob(int* nums, int numsSize) {
        int a=0,b=0;
        for(int i=0;i<numsSize;i++){
        	if(i%2==0) a=fmax(a+nums[i],b);
        	else b=fmax(b+nums[i],a);
        }
        return fmax(a,b);
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.