当前位置:网站首页>Leetcode 118, Yanghui triangle
Leetcode 118, Yanghui triangle
2022-04-22 12:56:00 【Die in a trap】
118、 Yang hui triangle
1) 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
2) analysis
iteration . The elements at both ends of each line and the elements in the middle are calculated separately . At both ends of each line are 1, Iterative calculation of the elements in the middle , Use the previous line to calculate the next line .
- Yanghui triangle's No
iYesiElements ; - The first element and the last element of each line of Yang Hui triangle are
1; - The third line of Yang Hui triangle begins , Elements not at both ends
res[i][j]=res[i-1][j-1]+res[i-1][j];
3)C++ Code
class Solution {
public:
vector<vector<int>> generate(int numRows) {
vector<vector<int>> res(numRows);
for(int i=0;i<numRows;i++){
res[i].resize(i+1);
res[i][0]=res[i][i]=1;
for(int j=1;j<i;j++){
res[i][j]=res[i-1][j-1]+res[i-1][j];
}
}
return res;
}
};
版权声明
本文为[Die in a trap]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204221216573810.html
边栏推荐
- @PreAuthorize注解做权限校验
- Machine learning 7- logistic regression to realize the binary classification of watermelon dataset 2.0
- R language changes dataframe data from long to wide: spread function of tidyr package and pivot of CDATA package_ to_ Rowrecs function, data Table package dcast function
- 51单片机案例(1)——利用DS1302实现实时时钟和可调时钟的功能
- April 21, 2022 s s s m framework integration @ lesson 1 s s m environment configuration & focus on practical operation. Summary in practice. The results are not shown here.
- 百度地图结合vr全景,全景地图模式让你出行更放心
- C#自定义Button实现源码
- Creation of multithreaded basic thread
- JS foundation 12
- Page d'inscription du projet Bookstore et vérification de la boîte aux lettres
猜你喜欢

C#之SQL数据库操作(源码)

【生活杂谈】中体平台教你如何提高彩票中奖率

自己动手写编译器:通过语法编译构建语法树并实现中间代码生成

Select the appropriate span combination for one span in MATLAB Bridge

11. Container with the most water

21. merge two ordered linked lists

3D application rotation album

动态规划 字符的最短距离

让cpolar获得固定TCP地址

17. Letter combination of telephone number
随机推荐
<JDBC> 获取数据库连接的五种方式:你真的get到了吗?
详解为什么OpenCV的直方图计算函数calcHist()计算出的灰度值为255的像素个数为0
The ABAQUS model of standardized steel box girder is established, and the plug-in of RSG is used for secondary development
Embedded development: three techniques for verifying sensors and communication data in embedded systems
[life gossip] Chinese sports platform teaches you how to improve the lottery winning rate
Under the pressure of sanctions, Russia plans to import electronic products in parallel through friendly countries
Mathematics - covariance
17. Letter combination of telephone number
Excel字符串拼接
R language data Table import data practice: data It is more convenient to set key, compound key, delete key and data join after setting key value. After setting key value, you can use keyby syntax ins
Redis本地连接查看数据
解决CMD命令不能连续执行的问题
Enterprise code static testing tool helix QAC - technical specifications
R语言编写决策曲线DCA(Decision Curve Analysis)函数、多条决策曲线分析DCA曲线可视化在同一图像中
百度地图结合vr全景,全景地图模式让你出行更放心
缩表牛:最后的狂欢
11. Container with the most water
Smart cultural tourism is gradually digitalized, and VR panorama promotes the integrated development of cultural tourism
R语言ggplot2可视化:ggplot2可视化将图像的图例(legend)移动到图像内部、自定义图例所处的位置
Is this open source project going to kill me?