当前位置:网站首页>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;
}
};
边栏推荐
- 单片机学习笔记之点亮led 灯
- 我那“不好惹”的00后下属:不差钱,怼领导,抵制加班
- 云计算安全扩展要求关注的安全目标和实现方式区分原则有哪些?
- JS function 返回多个值
- Realize the IP address home display function and number home query
- 10 pictures open the door of CPU cache consistency
- User management summary of mongodb
- Ways to improve the performance of raspberry pie
- JS缓动动画原理教学(超细节)
- [QNX Hypervisor 2.2用户手册]6.3.4 虚拟寄存器(guest_shm.h)
猜你喜欢

记一次 .NET 某新能源系统 线程疯涨 分析

2022-7-6 Leetcode27.移除元素——太久没有做题了,为双指针如此狼狈的一天

交付效率提升52倍,运营效率提升10倍,看《金融云原生技术实践案例汇编》(附下载)

迅为iTOP-IMX6ULL开发板Pinctrl和GPIO子系统实验-修改设备树文件

Esp32 ① compilation environment

室内ROS机器人导航调试记录(膨胀半径的选取经验)

Show the mathematical formula in El table

Cinnamon 任务栏网速

Ways to improve the performance of raspberry pie

MySQL error 28 and solution
随机推荐
高端了8年,雅迪如今怎么样?
118. 杨辉三角
Talk about pseudo sharing
得物客服热线的演进之路
JNA learning notes 1: Concepts
交付效率提升52倍,运营效率提升10倍,看《金融云原生技术实践案例汇编》(附下载)
Drawerlayout suppress sideslip display
xshell连接服务器把密钥登陆改为密码登陆
PAcP learning note 3: pcap method description
MongoDB的用户管理总结
分布式事务解决方案
What parameters need to be reconfigured to replace the new radar of ROS robot
ESP32构解工程添加组件
[QNX hypervisor 2.2 user manual]6.3.4 virtual register (guest_shm.h)
ESP32 ① 编译环境
Mongodb replication (replica set) summary
MySQL error 28 and solution
RealBasicVSR测试图片、视频
postgresql array类型,每一项拼接
1. Deep copy 2. Call apply bind 3. For of in differences