Got a Runtime Error for my C solution. Why?

  • 0
     * Return an array of arrays.
     * The sizes of the arrays are returned as *columnSizes array.
     * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().
    int** generate(int numRows, int** columnSizes)
    if (numRows <= 0)
        return NULL;
    *columnSizes = (int*)malloc(numRows*sizeof(int));
    int** ret = (int**)malloc(numRows*sizeof(int*)+(numRows+1)/2*numRows*sizeof(int));
    ret[0] = (int*)(numRows*sizeof(int*)+(void*)ret);
    ret[0][0] = 1;
    for(int i=1;i<numRows;i++)
        ret[i][0] = 1;
        ret[i][i] = 1;
        for(int j=1;j<i;j++)
    return ret;

Log in to reply

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