当前位置:网站首页>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;
}
边栏推荐
- Lumiprobe phosphide hexaethylene phosphide specification
- 狼人杀攻略:你当我好骗吗,我们相信谁!
- Instagram 为何从内容共享平台变成营销工具?独立站卖家如何利用该工具?
- 学习笔记【gumbel softmax】
- 求各种极限的方法
- 新版国标GB28181视频平台EasyGBS如何配置WebRTC视频流格式播放?
- Lumiprobe free radical analysis h2dcfda instructions
- ubuntu14安装MySQL并配置root账户本地与远程访问
- B2B e-commerce platform solution for fresh food industry to improve the standardization and transparency of enterprise transaction process
- Netease games, radical going to sea
猜你喜欢
Enabling "new Chinese enterprises", SAP process automation landing in China
ubuntu14安装MySQL并配置root账户本地与远程访问
B2B e-commerce platform solution for fresh food industry to improve the standardization and transparency of enterprise transaction process
数字化转型企业成功的关键,用数据创造价值
【To .NET】C#集合类源码解析
Lake Shore continuous flow cryostat transmission line
Lake shore optimag superconducting magnet system om series
云服务器ECS夏日省钱秘籍,这次@老用户快来领走
June issue | antdb database participated in the preparation of the "Database Development Research Report" and appeared on the list of information technology and entrepreneurship industries
Lumiprobe phosphide hexaethylene phosphide specification
随机推荐
axure不显示元件库
Methods of finding various limits
The use of subplot function in MATLAB
Go语言高级
Parallelism, concurrency and life cycle of threads
Dlib+opencv library for fatigue detection
Witness the times! "The future of Renji collaboration has come" 2022 Hongji ecological partnership conference opens live broadcast reservation
数字化转型企业成功的关键,用数据创造价值
uni-app商品分类
Digital business cloud: from planning to implementation, how does Minmetals Group quickly build a new pattern of digital development?
XML语法、约束
Lumiprobe free radical analysis h2dcfda instructions
nacos配置文件发布失败,请检查参数是否正确的解决方案
如何正确使用Vertx操作Redis(3.9.4带源码分析)
PostgreSQL varchar[] array type operation
Love business in Little Red Book
Boost the development of digital economy and consolidate the base of digital talents - the digital talent competition was successfully held in Kunming
奔赴山海之前,毕业季一定要做的那些事情
MATLAB中subplot函数的使用
Reading the paper [learning to discretely compose reasoning module networks for video captioning]