当前位置:网站首页>118. 杨辉三角
118. 杨辉三角
2022-07-07 11:38:00 【yitahutu79】
给定一个非负整数 numRows,生成「杨辉三角」的前 numRows 行。
在「杨辉三角」中,每个数是它左上方和右上方的数的和。
示例 1:
输入: numRows = 5
输出: [[1],[1,1],[1,2,1],[1,3,3,1],[1,4,6,4,1]]
示例 2:
输入: numRows = 1
输出: [[1]]
提示:
1 <= numRows <= 30
class Solution {
public:
vector<vector<int>> generate(int numRows) {
vector<vector<int>> ret(numRows);
for (int i = 0; i < numRows; i++) {
ret[i].resize(i+1);
for (int j = 0; j <= i; j++) {
if (j == 0 || j == i) {
ret[i][j] = 1;
}
else {
ret[i][j] = ret[i-1][j-1] + ret[i-1][j];
}
}
}
return ret;
}
};
边栏推荐
- Shell batch file name (excluding extension) lowercase to uppercase
- MongoDB 遇见 spark(进行整合)
- Cloud detection 2020: self attention generation countermeasure network for cloud detection in high-resolution remote sensing images
- Read PG in data warehouse in one article_ stat
- Pcap learning notes II: pcap4j source code Notes
- [learning notes] zkw segment tree
- 云计算安全扩展要求关注的安全目标和实现方式区分原则有哪些?
- MongoDB优化的几点原则
- MongoDB的导入导出、备份恢复总结
- Deep understanding of array related problems in C language
猜你喜欢
2022-7-7 Leetcode 844.比较含退格的字符串
My "troublesome" subordinates after 00: not bad for money, against leaders, and resist overtime
centso7 openssl 报错Verify return code: 20 (unable to get local issuer certificate)
Milkdown control icon
Realize the IP address home display function and number home query
OSI 七层模型
Cloud detection 2020: self attention generation countermeasure network for cloud detection in high-resolution remote sensing images
Isprs2021/ remote sensing image cloud detection: a geographic information driven method and a new large-scale remote sensing cloud / snow detection data set
LeetCode简单题分享(20)
Xshell connection server changes key login to password login
随机推荐
室内ROS机器人导航调试记录(膨胀半径的选取经验)
How to make the new window opened by electorn on the window taskbar
[learning notes] zkw segment tree
Move base parameter analysis and experience summary
Realize the IP address home display function and number home query
Esp32 construction engineering add components
[dark horse morning post] Huawei refutes rumors about "military master" Chen Chunhua; Hengchi 5 has a pre-sale price of 179000 yuan; Jay Chou's new album MV has played more than 100 million in 3 hours
648. 单词替换 : 字典树的经典运用
将数学公式在el-table里面展示出来
单片机学习笔记之点亮led 灯
[1] Basic knowledge of ros2 - summary version of operation commands
2022-7-7 Leetcode 844.比较含退格的字符串
ESP32 ① 编译环境
Distributed transaction solution
Some principles of mongodb optimization
Realbasicvsr test pictures and videos
Cinnamon Applet 入门
Flink | multi stream conversion
存储过程的介绍与基本使用
Scripy tutorial classic practice [New Concept English]