当前位置:网站首页>118. Yanghui triangle
118. Yanghui triangle
2022-07-07 13:37:00 【yitahutu79】
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
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;
}
};
边栏推荐
- 分布式事务解决方案
- 【面试高频题】难度 2.5/5,简单结合 DFS 的 Trie 模板级运用题
- MongoDB复制(副本集)总结
- 为租客提供帮助
- Redis只能做缓存?太out了!
- [etc.] what are the security objectives and implementation methods that cloud computing security expansion requires to focus on?
- Summary of import, export, backup and recovery of mongodb
- 10 pictures open the door of CPU cache consistency
- MySQL error 28 and solution
- ROS机器人更换新雷达需要重新配置哪些参数
猜你喜欢
Getting started with cinnamon applet
Navicat run SQL file import data incomplete or import failed
Indoor ROS robot navigation commissioning record (experience in selecting expansion radius)
迅为iTOP-IMX6ULL开发板Pinctrl和GPIO子系统实验-修改设备树文件
2022-7-6 使用SIGURG来接受外带数据,不知道为什么打印不出来
DID登陆-MetaMask
室內ROS機器人導航調試記錄(膨脹半徑的選取經驗)
ESP32构解工程添加组件
ESP32 ① 编译环境
得物客服热线的演进之路
随机推荐
Detr introduction
Scripy tutorial classic practice [New Concept English]
118. 杨辉三角
[QNX hypervisor 2.2 user manual]6.3.4 virtual register (guest_shm.h)
Cinnamon 任务栏网速
Japanese government and enterprise employees got drunk and lost 460000 information USB flash drives. They publicly apologized and disclosed password rules
Deep understanding of array related problems in C language
PAcP learning note 3: pcap method description
Thread pool reject policy best practices
华为镜像地址
Cmake learning and use notes (1)
PHP - laravel cache
数据库系统概论-第一章绪论【概念模型、层次模型和三级模式(外模式、模式、内模式)】
MongoDB的导入导出、备份恢复总结
得物客服热线的演进之路
分布式事务解决方案
单片机学习笔记之点亮led 灯
Pcap learning notes II: pcap4j source code Notes
[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
Solve the cache breakdown problem