leetcode-1086. 前五科的均分-C语言

/**
 * Return an array of arrays of size *returnSize.
 * The sizes of the arrays are returned as *returnColumnSizes array.
 * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().
 */

int cmp(const void *arr1, const void *arr2) {
    int *ar1 = *(int **)arr1, *ar2 = *(int **)arr2;
    
    if(ar1[0] != ar2[0]) return ar2[0] - ar1[0];
    
    return ar2[1] - ar1[1];
}


#define LEN 1000

int** highFive(int** items, int itemsSize, int* itemsColSize, int* returnSize, int** returnColumnSizes){
    int **ret = (int **)malloc(sizeof(int *) * LEN);
    int i, j, last=-1, cnt = 0;
    
    qsort(items, itemsSize, sizeof(int *), cmp);
    
    memset(ret, 0, sizeof(int *) * LEN);
    
    for(i=0; i

你可能感兴趣的:(LeetCode)