Share my c solution


  • 1
    E
    int** generate(int numRows, int** columnSizes, int* returnSize) {
        if(!columnSizes) return 0;
        if(!returnSize||numRows==0) return 0;
        int **returnArray=(int **)malloc(numRows*sizeof(int *));
        int *columnSizesArray=malloc(sizeof(int)*numRows);
        
        *returnSize=0;
        int i=0;
        int j=0;
        for(i=0;i<numRows;i++){
               returnArray[i]=(int *)malloc(sizeof(int)*(i+1));
              //columnSizes[i]=(int *)malloc(sizeof(int)*(1));
              columnSizesArray[i]=i+1;
                for(j=0;j<i+1;j++)
                {
                    if(j==0) 
                    {
                        returnArray[i][j]=1;
                    }else if(j==i)
                    {
                        returnArray[i][j]=1;
                    }else{
                        returnArray[i][j]=returnArray[i-1][j]+returnArray[i-1][j-1];
                    }
                    
                }
                (*returnSize)++;
                //columnSizes[i][0]=(int)(sizeof(returnArray[i]));
            }
        *columnSizes=columnSizesArray;
        return returnArray;
    }

Log in to reply
 

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