LeetCode OJ:Pascal's Triangle(帕斯卡三角)
2024-09-04 17:56:18
Given numRows, generate the first numRows of Pascal's triangle.
For example, given numRows = 5,
Return
[
[1],
[1,1],
[1,2,1],
[1,3,3,1],
[1,4,6,4,1]
]
帕斯卡三角,很简单的问题,见代码:
class Solution {
public:
vector<vector<int>> generate(int numRows) {
vector<vector<int>> ret;
vector<int> tmpVec;
ret.clear();
tmpVec.clear();
for(int i = ; i < numRows; ++i){
if(i == ){
tmpVec.push_back();
}else{
for(int j = ; j <= i; ++j){
if(j == ) tmpVec.push_back();
else if(j == i) tmpVec.push_back();
else tmpVec.push_back(ret[i - ][j - ] + ret[i - ][j]);
}
}
ret.push_back(tmpVec);
tmpVec.clear();
}
return ret;
}
};
最新文章
- 【30集iCore3_ADP出厂源代码(ARM部分)讲解视频】30-3 底层驱动之LED_蜂鸣器
- Ubuntu 14.04 Trusty安装java环境
- 中国电信大亚DP607光猫破解,设置路由,wifi!关闭远程管理,改连接限制,SN码查询!
- linux_过程问题记录
- TAG的用法和用途[转]
- 变量-if else while-运算符
- php面向对象4
- NFS+sersync+Keepalived高可用方案
- Vue2 Virtual DOM
- 插件使用一颜色选择器---cxColor
- Linux find 命令参数大全及示例
- Golang channel 用法简介
- 开始试用Dynamics 365
- laravel数据迁移
- python3【基础】-文件操作
- 安卓中AsyncTask的基本使用
- Hadoop2.X分布式集群部署
- HDU-3592 World Exhibition
- 乘法逆元__C++
- BZOJ3224普通平衡树
热门文章
- (3.8)常用知识-临时表、表变量、CTE的对比
- 使用Free命令查看Linux服务器内存使用状况(-/+ buffers/cache详解)
- 如何根据一些参数,自动生成一个简单的maven工程,然后导入Eclipse直接使用?(maven命令)
- 第六课 GDB调试 (上)
- idea 快键件大全
- ZOJ 3261 Connections in Galaxy War (逆向+带权并查集)
- CSS3鼠标悬停边框线条动画按钮
- 0927-转载:SSM:spring+springmvc+mybatis框架中的XML配置文件功能详细解释
- iOS动画进阶 - 手摸手教你写 Slack 的 Loading 动画
- maven说明