当前位置:网站首页>118. Yanghui triangle
118. Yanghui triangle
2022-07-01 19:35:00 【Mr Gao】
Given a nonnegative integer numRows, Generate 「 Yang hui triangle 」 Before numRows That's ok .
stay 「 Yang hui triangle 」 in , Each number is the sum of the numbers at the top left and right of it .
Example 1:
Input : numRows = 5
Output : [[1],[1,1],[1,2,1],[1,3,3,1],[1,4,6,4,1]]
Example 2:
Input : numRows = 1
Output : [[1]]
The solution code is as follows :
/** * 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){
*returnSize=numRows;
* returnColumnSizes=(int *)malloc(sizeof(int)*numRows);
int **re=(int **)malloc(sizeof(int*)*numRows);
int i;
for(i=0;i<numRows;i++){
(*returnColumnSizes)[i]=i+1;
re[i]=(int*)malloc(sizeof(int)*(i+1));
}
int j;
re[0][0]=1;
for(i=1;i<numRows;i++){
for(j=0;j<i+1;j++){
int a,b;
// printf("df1");
if(j==0){
a=0;
}
else{
a=re[i-1][j-1];
}
// printf("df2");
if(j==i){
b=0;
}
else{
b=re[i-1][j];
}
re[i][j]=a+b;
}
// printf("df3");
}
// printf("dfsdf");
return re;
}
边栏推荐
猜你喜欢
随机推荐
Solidity - 合约结构 - 错误(error)- ^0.8.4版本新增
Dlib+opencv library for fatigue detection
记一次 .NET 差旅管理后台 CPU 爆高分析
见证时代!“人玑协同 未来已来”2022弘玑生态伙伴大会开启直播预约
Bao, que se passe - t - il si le serveur 100 + O & M a mal à la tête? Utilisez le majordome xingyun!
Lumiprobe phosphide hexaethylene phosphide specification
MySQl的基本使用
Solidity - contract structure - error - ^0.8.4 NEW
Interview questions for audio and video positions in Dachang -- today's headline
win10下使用msys+vs2019编译ffmpeg源码
[pytorch record] distributed training dataparallel and distributeddataparallel of the model
精耕渠道共謀發展 福昕攜手偉仕佳傑開展新產品培訓大會
为什么一定要从DevOps走向BizDevOps?
Dom4J解析XML、Xpath检索XML
赋能「新型中国企业」,SAP Process Automation 落地中国
MFC中如何重绘CListCtrl的表头
GetMessage底层机制分析
A brief understanding of white box encryption technology
241. Different Ways to Add Parentheses
AAAI2020: Real-time Scene Text Detection with Differentiable Binarization









