0 ms solution in C


  • 0
    S

    The solution is same as Maximum coin sum problem

    int maxof(int a, int b){

    return a>b?a:b;
    

    }

    int rob(int* nums, int numsSize){

    if(numsSize==0)
        return 0;
        
    if(numsSize==1)
        return nums[0];
    

    //for i>0

    for(int i=1;i<numsSize;i++){
        nums[i]=maxof(nums[i]+nums[i-2],nums[i-1]);
    }        
    
    return nums[numsSize-1];
    

    }


Log in to reply
 

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