Pascal's Triangle II
2015-07-04 14:26
357 查看
[code]class Solution { public: vector<vector<int>> generate(int numRows) { if(numRows == 0) { vector<vector<int>> tmpLarge; return tmpLarge; } if(numRows == 1) { vector<int> tmp; vector<vector<int>> tmpLarge; tmp.push_back(1); //"return tmpLarge.push_back(tmp);" is error tmpLarge.push_back(tmp); return tmpLarge; } vector<vector<int> > smallResult = generate(numRows - 1); vector<int> tmp; smallResult.push_back(tmp); smallResult[numRows - 1].push_back(1); for(int i = 0; i <= numRows - 3; i++) { smallResult[numRows - 1].push_back(smallResult[numRows - 2][i] + smallResult[numRows - 2][i + 1]); } smallResult[numRows - 1].push_back(1); return smallResult; } vector<int> getRow(int rowIndex) { return generate(rowIndex + 1)[rowIndex]; } };
相关文章推荐
- 第二章:创建框架和窗口
- 微信开发 支付开发redirect_uri参数错误解决办法
- 整数类型
- c++ 适配器
- Leetcode 202 Happy Number
- 多线程编程面试题
- java教程网
- Leetcode 217 Contains Duplicate
- Dynamics CRM 2015 Update 1 系列(5): 获取最近更新的数据 - RetrieveEntityRequest
- 手机触屏的js事件
- 第一次作业的补充说明
- Leetcode 219 Contains Duplicate II
- 磁盘测速
- SQL Server ->> GROUPING SETS, CUBE, ROLLUP, GROUPING, GROUPING_ID
- 【C/C++相关】论程序员写技术博客的重要性
- [C#] 可空类型的实现原理
- 用ftp命令实现主机文件批量更新
- Eclipse 中的GitHub插件
- mysql relay_log_info_repository和master_info_repository
- Java彻底 - WEB容器的侦听具体解释 ServletContextListener