Leetcode 118. Pascal's Triangle

Given numRows, generate the first numRows of Pascal's triangle.

For example, given numRows = 5,
Return

[
     [1],
    [1,1],
   [1,2,1],
  [1,3,3,1],
 [1,4,6,4,1]
]

分析

很简单的二维数组,杨辉三角,上一行的两数相加的和放在下一行。

/**
 * Return an array of arrays.
 * 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** generate(int numRows, int** columnSizes) {
    int **ans=(int **)malloc(sizeof(int*)*numRows);
    *columnSizes=(int*)malloc(sizeof(int)*numRows);
    for(int i=0;i

你可能感兴趣的:(Leetcode 118. Pascal's Triangle)