C very simple and clean solution,with qsort(),5lines


  • 0
    W
    int cmp( const void *a , const void *b ) 
    { 
    	return *(int *)a -*(int *)b; 
    } 
    int maximumProduct(int* nums, int numsSize) {
        qsort(nums,numsSize,sizeof(int),cmp);
        int maxret1=nums[numsSize-1]*nums[numsSize-2]*nums[numsSize-3];
        int maxret2=nums[numsSize-1]*nums[1]*nums[0];
        return maxret1>maxret2?maxret1:maxret2;
    }
    

Log in to reply
 

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