LeetCode 118. Pascal's Triangle
我在写这个的时候,没有懂要返回一个数组怎么写
于是报了错误:
https://blog.csdn.net/qq_32768743/article/details/89349649

后面看了https://leetcode.com/problems/pascals-triangle/discuss/244983/MY-C-SOLUTION
才知道原来要这样
通过int** columnSizes传入参数
要这样才能把参数带出去

*columnSizes = (int**)malloc(sizeof(int) * numRows);

最后的结果
LeetCode 118. Pascal's Triangle
代码

int** generate(int numRows, int** columnSizes) {
    int **ret = (int**)malloc(sizeof(int*) * numRows);
   *columnSizes = (int**)malloc(sizeof(int) * numRows);
    for(int i=0; i<numRows; i++) {
        ret[i] = (int*)malloc(sizeof(int) * (i+1));
        (*columnSizes)[i]=i+1;
        ret[i][0] = 1;
        ret[i][i] = 1;
        if (i > 0) {
            for(int j=1; j<i;j++) {
                ret[i][j] = ret[i-1][j-1] + ret[i-1][j];
            }
        }
    }
    return ret;
}

相关文章:

  • 2021-10-08
  • 2021-11-15
  • 2021-08-20
  • 2021-08-13
猜你喜欢
  • 2021-12-28
  • 2022-01-25
  • 2021-09-28
  • 2021-11-01
  • 2021-09-10
  • 2021-04-19
相关资源
相似解决方案