指针让人很费解,这题做的很迷糊,看了题解才勉强通过。
/**
* 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** generate(int numRows, int* returnSize, int** returnColumnSizes){
int** a = malloc(sizeof(int*) * numRows);
*returnSize = numRows;
*returnColumnSizes = malloc(sizeof(int) * numRows);
for(int i = 0; i < numRows; i++){
a[i] = malloc(sizeof(int) * (i+1));
(*returnColumnSizes)[i] = i+1;
a[i][0] = a[i][i] = 1;
for(int j = 1; j < i; j++){
a[i][j] = a[i-1][j-1] + a[i-1][j];
}
}
return a;
}