当前位置:网站首页>118. 杨辉三角
118. 杨辉三角
2022-07-01 18:45:00 【Mr Gao】
给定一个非负整数 numRows,生成「杨辉三角」的前 numRows 行。
在「杨辉三角」中,每个数是它左上方和右上方的数的和。
示例 1:
输入: numRows = 5
输出: [[1],[1,1],[1,2,1],[1,3,3,1],[1,4,6,4,1]]
示例 2:
输入: numRows = 1
输出: [[1]]
解题代码如下:
/** * 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;
}
边栏推荐
- Lake shore M91 fast hall measuring instrument
- PostgreSQL varchar[] 数组类型操作
- Instagram 为何从内容共享平台变成营销工具?独立站卖家如何利用该工具?
- 论文阅读【Discriminative Latent Semantic Graph for Video Captioning】
- 241. Different Ways to Add Parentheses
- AAAI2020: Real-time Scene Text Detection with Differentiable Binarization
- 测试自学人必看:软件测试如何找测试项目?
- The use of subplot function in MATLAB
- 见证时代!“人玑协同 未来已来”2022弘玑生态伙伴大会开启直播预约
- nacos配置文件发布失败,请检查参数是否正确的解决方案
猜你喜欢
Chinese and English instructions human soluble advanced glycation end products receptor (sRAGE) ELISA Kit
Dom4j parsing XML, XPath retrieving XML
Bao, que se passe - t - il si le serveur 100 + O & M a mal à la tête? Utilisez le majordome xingyun!
Cdga | if you are engaged in the communication industry, you should get a data management certificate
Lake shore M91 fast hall measuring instrument
kubernetes命令入门(namespaces,pods)
Lake Shore—OptiMag 超导磁体系统 — OM 系列
Case sharing: basic networking configuration of QinQ
智慧防疫系统为建筑工地复工复产提供安全保障
微信公众号开发相关流程及功能介绍
随机推荐
The difference between indexof and includes
Write it down once Net travel management background CPU Explosion Analysis
Intensive cultivation of channels for joint development Fuxin and Weishi Jiajie held a new product training conference
Witness the times! "The future of Renji collaboration has come" 2022 Hongji ecological partnership conference opens live broadcast reservation
白盒加密技术浅理解
Go Language Advanced
原生js打造日程表-支持鼠标滚轮滚动选择月份-可以移植到任何框架中
Introduction to relevant processes and functions of wechat official account development
任务:拒绝服务DoS
What must be done in graduation season before going to Shanhai
论文阅读【Discriminative Latent Semantic Graph for Video Captioning】
寶,運維100+服務器很頭疼怎麼辦?用行雲管家!
Is PMP cancelled??
Parallelism, concurrency and life cycle of threads
Learning notes - steps of JDBC connection database operation
精耕渠道共谋发展 福昕携手伟仕佳杰开展新产品培训大会
一次SQL优化,数据库查询速度提升 60 倍
MySQL common graphics management tools | dark horse programmers
Team up to learn! 14 days of Hongmeng equipment development "learning, practicing and testing" practical camp, free of charge!
axure不显示元件库