当前位置:网站首页>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;
}
边栏推荐
- GetMessage底层机制分析
- Lean thinking: source, pillar, landing. I understand it after reading this article
- 【6.24-7.1】写作社区精彩技术博文回顾
- DTD建模
- [info() method in org.slf4j.logger]
- What must be done in graduation season before going to Shanhai
- Download (export) PDF template file (such as approval form), and report error: invalid nested tag * * * found, expected closing tag***
- Chinese and English instructions human soluble advanced glycation end products receptor (sRAGE) ELISA Kit
- Solidity - 合约结构 - 错误(error)- ^0.8.4版本新增
- ECS summer money saving secret, this time @ old users come and take it away
猜你喜欢
DTD modeling
商业智能BI开发和报表开发有什么本质区别?
使用环信提供的uni-app Demo,快速实现一对一单聊
Witness the times! "The future of Renji collaboration has come" 2022 Hongji ecological partnership conference opens live broadcast reservation
What must be done in graduation season before going to Shanhai
Shell高级进阶
AAAI2020: Real-time Scene Text Detection with Differentiable Binarization
为什么一定要从DevOps走向BizDevOps?
Solidity - truncated and checked modes of arithmetic operations - new features of 0.8.0
ddr4测试-2
随机推荐
寶,運維100+服務器很頭疼怎麼辦?用行雲管家!
Ffmpeg avframe to cv:: mat
EasyGBS网络不稳定情况下重复请求视频拉流问题的优化
Go Language Advanced
Download (export) PDF template file (such as approval form), and report error: invalid nested tag * * * found, expected closing tag***
【无标题】
从零开始学 MySQL —数据库和数据表操作
torch.nn.functional.interpolate函数
Methods of finding various limits
Werewolf killing strategy: do you think I'm easy to cheat? Who do we believe!
Implement a Prometheus exporter
云服务器ECS夏日省钱秘籍,这次@老用户快来领走
[English grammar] Unit1 articles, nouns, pronouns and numerals
Learning notes [Gumbel softmax]
OpenCV视频质量诊断----视频遮挡诊断
音视频、编解码相关电子书、小工具,打包奉送!
SIP protocol of gb28181
Chinese and English instructions human soluble advanced glycation end products receptor (sRAGE) ELISA Kit
DTD建模
使用环信提供的uni-app Demo,快速实现一对一单聊