C Question , Why return matrix always blank?


  • 0
    H
    /**
     * Return an array of arrays of size *returnSize.
     * 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** updateMatrix(int** matrix, int matrixRowSize, int *matrixColSizes, int** columnSizes, int* returnSize) {
           int **return_matrix = (int**)malloc(sizeof(int*) * 3);
       for(int k = 0; k < 3; k++)
       {
          return_matrix[k] = (int *)malloc(sizeof(int) * (3));
          *(*(return_matrix+k)) = 1;
          *((*(return_matrix+k))+1) = 1;
          *((*(return_matrix+k))+1) = 1;
       } 
       *matrixColSizes = 3;
       *(matrixColSizes+1) = 3;
       *(matrixColSizes+2) = 10;
       *returnSize = 3;
    //   returnSize[1] = 3;
    //   returnSize[2] = 3;
       
       
    //   return_matrix[1][1] = 1;
       return matrix;
    }
    

    Your input

    [[0,0,0],[0,1,0],[0,0,0]]

    Your answer

    [[],[],[]]


Log in to reply
 

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