当前位置:网站首页>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;
}
边栏推荐
- 音频编解码基础知识
- MySQl的基本使用
- 【org.slf4j.Logger中info()方法】
- Dlib+opencv library for fatigue detection
- [English grammar] Unit1 articles, nouns, pronouns and numerals
- Specification of lumiprobe reactive dye indocyanine green
- How to solve the problem of splash screen when the main and sub code streams of easygbs are h.265?
- Dom4j parsing XML, XPath retrieving XML
- Helium transmission line of lake shore cryostat
- ubuntu14安装MySQL并配置root账户本地与远程访问
猜你喜欢

ECS summer money saving secret, this time @ old users come and take it away

大厂音视频职位面试题目--今日头条

nacos启动失败问题解决与总结
![Reading the paper [learning to discretely compose reasoning module networks for video captioning]](/img/a2/acdaebeb67ec4bcb01c8ff4bbd1d1e.png)
Reading the paper [learning to discretely compose reasoning module networks for video captioning]

Crunch简介、安装,使用Crunch制作密码字典
Use the uni app demo provided by Huanxin to quickly realize one-on-one chat

案例分享:QinQ基本组网配置

Solidity - 算术运算的截断模式(unchecked)与检查模式(checked)- 0.8.0新特性

Bao, que se passe - t - il si le serveur 100 + O & M a mal à la tête? Utilisez le majordome xingyun!

optaplanner学习笔记(一)案例Cloud balance
随机推荐
智慧防疫系统为建筑工地复工复产提供安全保障
Solidity - 算术运算的截断模式(unchecked)与检查模式(checked)- 0.8.0新特性
奔赴山海之前,毕业季一定要做的那些事情
Junit单元测试框架详解
ddr4测试-2
Learning records of building thingsboard, an Internet of things platform
uni-app微信小程序一键登录获取权限功能
[pytorch record] distributed training dataparallel and distributeddataparallel of the model
ffmpeg 音频相关命令
下载(导出)pdf模板文件(比如:审批单),报错:Invalid nested tag *** found, expected closing tag ***
XML syntax, constraints
商业智能BI开发和报表开发有什么本质区别?
学习笔记-JDBC连接数据库操作的步骤
[go ~ 0 to 1] day 5 July 1 type alias, custom type, interface, package and initialization function
H264编码profile & level控制
optaplanner学习笔记(一)案例Cloud balance
Manufacturing SRM management system supplier all-round closed-loop management, to achieve procurement sourcing and process efficient collaboration
Download (export) PDF template file (such as approval form), and report error: invalid nested tag * * * found, expected closing tag***
【6.24-7.1】写作社区精彩技术博文回顾
ES6中的代理proxy