C Solution, use quick qsort


  • 0
    J

    int arrayPairSum(int* nums, int numsSize) {
    int i=0,sum=0;
    int cmp(const void *a, const void b) {
    return(
    (int )a>(int *)b); //升序
    }
    qsort(nums, numsSize, sizeof(int), cmp);
    for(i=0;i<numsSize;i+=2){
    sum+=nums[i];
    }
    return sum;
    }


Log in to reply
 

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