当前位置:网站首页>Leetcode notes 118. Yang Hui triangle
Leetcode notes 118. Yang Hui triangle
2022-07-28 13:24:00 【Lyrig~】
Leetcode note 118. Yang hui triangle
Title Description
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]]
Tips :
1 <= numRows <= 30
Ideas
It's simulation , Pay attention to recurrence relationship a n s [ i ] [ j ] = a n s [ i − 1 ] [ j − 1 ] + a n s [ i − 1 ] [ j ] ( j ! = 0 ∣ ∣ i ) a n s [ i ] [ j ] = 1 ( j = 0 ∣ ∣ i ) \mathcal{ans[i][j]} = ans[i - 1][j - 1] +ans[i-1][j](j!=0 ||i)\\ ans[i][j]=1(j = 0 ||i) ans[i][j]=ans[i−1][j−1]+ans[i−1][j](j!=0∣∣i)ans[i][j]=1(j=0∣∣i)
among ans[i][j] Means Yang Hui triangle No i Xing di j individual
Code
class Solution {
public:
vector<vector<int>> generate(int numRows) {
vector<vector<int>> ans;
for(int i = 0; i < numRows; ++ i)
{
ans.push_back(vector<int>(i + 1));
for(int j = 0; j < i + 1; ++j)
{
if(j == 0 || j == i)
{
ans[i][j] = 1;
}
else ans[i][j] = ans[i - 1][j - 1] + ans[i - 1][j];
}
}
return ans;
}
};
边栏推荐
- Storage model: big end and small end
- Compare the new and old data to find the added and deleted ones
- Gamestop bear market entered NFT trading, and established game retailers took advantage of Web3 to make a second spring
- Stepless dimming colorful RGB mirror light touch chip-dlt8s12a-jericho
- 【嵌入式C基础】第3篇:常量和变量
- With 433 remote control UV lamp touch chip-dlt8sa20a-jericho
- Leetcode 笔记 118. 杨辉三角
- How does kotlin help you avoid memory leaks?
- Tidb 6.x in action was released, a summary of 6.x practices that condense the collective wisdom of the community!
- 夜神模拟器抓包微信小程序
猜你喜欢
![[matlab] IIR filter](/img/60/8e666bff3d458cdd9367ca45112b92.png)
[matlab] IIR filter

【嵌入式C基础】第5篇:原码/反码/补码

Smart touch screen LCD bathroom mirror light touch chip-dlt8t02s-jericho

《TiDB 6.x in Action》发布,凝聚社区集体智慧的 6.x 实践汇总!

Margin calculation

How much do you know about JVM memory management

Aragon creates Dao polygon BSC test network

MySQL 实践篇 —— 主从复制

leetcdoe-342. 4的幂

Definition of option basis
随机推荐
[embedded C foundation] Part 7: detailed introduction to C language process control
Dry goods -- encapsulated anti shake and throttling method in the project
Pointnet++ Chinese Translation
[FPGA]: ise and Modelsim joint simulation
黑猫带你学eMMC协议第24篇:eMMC的总线测试程序详解(CMD19 & CMD14)
Chinese translation of pointnet:deep learning on point sets for 3D classification and segmentation
docker部署mysql 实现远程连接[通俗易懂]
kotlin学习笔记3——Lambda编程
ES6 null merge operator (?)
nport串口服务器配置网址(串口服务器是不是网口转串口)
管理区解耦架构见过吗?能帮客户搞定大难题的
Change password, confirm password verification antd
JS method of splitting strings
Black Scholes Merton European option pricing formula
Protobuf data exchange format
Black cat takes you to learn EMMC protocol chapter 27: what is EMMC's dynamic capacity?
Sub thread update UI full solution
Protective bearish strategy
[embedded C foundation] Part 5: original code / inverse code / complement code
[embedded C foundation] Part 8: explanation of C language array