力扣刷题,杨辉三角出现bug

问题遇到的现象和发生背景

LeetCode刷题遇到程序bug ,118.杨辉三角

显示一堆奇怪的错误,看不懂..

不过我感觉我的算法应该没问题

问题相关代码,请勿粘贴截图

/**

  • 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** yh = (int**)malloc(sizeof(int)*numRows);
    int cnt = 1;
    for(int i = 0;i
    {
      *returnColumnSizes[i] = cnt++;
    
    }
    *returnSize = numRows;
    for (int i = 0;i < numRows;i++)
    {
      yh[i] = (int*)malloc(sizeof(int)*(i + 1));
      for(int j = 0;j < i + 1;j++)
      {
          if (j == 0 || j == i)
              yh[i][j] = 1;
          else
          {
              yh[i][j] = yh[i - 1][j] + yh[i - 1][j - 1];
          }
      }
    
    }
    return yh;
    }
运行结果及报错内容

img

我想要达到的结果

求指点

int** yh = (int**)malloc(sizeof(int) * numRows);
这里应该是sizeof(int*),不是sizeof(int),这里分配的是行指针空间

  • returnSize = numRows; 这个肯定有问题,numRows也是传入参数,还有必要这么赋值一下?这个size应该是整个二维数组的大小吧