Skip to content

Instantly share code, notes, and snippets.

@XcqRomance
Created December 3, 2018 07:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save XcqRomance/62d5977ba1da9fea6131b4cf08494de1 to your computer and use it in GitHub Desktop.
Save XcqRomance/62d5977ba1da9fea6131b4cf08494de1 to your computer and use it in GitHub Desktop.
// 帕斯卡三角形 杨辉三角
int** generate(int numRows, int** columnSizes) {
if(numRows<=0) return NULL;
int **ret=(int **)malloc(numRows*sizeof(int *));
int row,column;
*columnSizes = (int *)malloc(numRows*sizeof(int));
//printf("成功初始化数组与行数矩阵\n");
for(row=0;row<numRows;row++)
{(*columnSizes)[row]=row+1;
ret[row]=(int*)malloc((row+1)*sizeof(int));
}
for(row=0;row<numRows;row++)
{
ret[row][0]=1;
ret[row][row]=1;
}
//printf("初始化数组成功\n");
if(numRows<=2){
return ret;
}
for(row=2;row<numRows;row++){
for(column=1;column<row;column++)
ret[row][column]=ret[row-1][column-1]+ret[row-1][column];
}
return ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment