哪位大佬帮我看看,我这么写有什么问题?明明执行都给过了,提交就报错。
/**
* 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 compare(const void* a,const void* b);
int** merge(int** intervals, int intervalsSize, int* intervalsColSize, int* returnSize, int** returnColumnSizes){
qsort(intervals,intervalsSize,sizeof(intervals[0]),compare);
int** arr=(int**)malloc(sizeof(int*)*intervalsSize);
int i,j,cnt;
for(i=0;i<intervalsSize;++i)
{
arr[i]=(int*)malloc(*intervalsColSize*sizeof(int));
}
i=0;
cnt=0;
j=i;
arr[cnt][0]=intervals[j][0];
while(i<intervalsSize)
{
if(intervals[j][1]>=intervals[i][0])
{
++i;
}else{
arr[cnt++][1]=intervals[i-1][1];
j=i;
arr[cnt][0]=intervals[j][0];
}
}
arr[cnt++][1]=intervals[i-1][1];
*returnSize=cnt;
int* retColSize=(int*)malloc(sizeof(int)*cnt);
for(i=0;i<cnt;++i)
{
retColSize[i]=2;
}
*returnColumnSizes=retColSize;
return arr;
}
int compare(const void* a,const void* b)
{
const int* n1=*(int**)a;
const int* n2=*(int**)b;
int ret=n1[0]-n2[0];
if(ret==0)
{
ret=n1[1]-n2[1];
}
return ret;
}