LeetCode Algorithms #66 <Pascal's Triangle>
2016-04-01 22:12
489 查看
Given numRows, generate the first numRows of Pascal's triangle.
For example, given numRows = 5,
Return
思路:
虽然我希望再简单的题我也能记录下自己的思路,但这道题我真的不知道说啥。
解:
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>> result; for(int rowIndex = 0; rowIndex < numRows; rowIndex++) { vector<int> rowVector; for(int idx = 0; idx < rowIndex+1; idx++) { if(idx == 0 || idx == rowIndex) { rowVector.push_back(1); continue; } rowVector.push_back(result[rowIndex-1][idx-1] + result[rowIndex-1][idx]); } result.push_back(rowVector); } return result; } };
相关文章推荐
- Django视图和网址
- LeetCode Algorithms #26 <Remove Duplicates from Sorted Array>
- 【Google Code Jam】Reverse Words
- LeetCode Algorithms #66 <Remove Element>
- Codeforces 367A Sereja and Algorithm 【规律】
- LeetCode Algorithms #27 <Remove Element>
- HDU 5642 King's Order
- just proxy 代理工具 上谷歌google 2016年最新
- 窗体透明,但窗体上的控件不透明(简单好用)good
- Codeforces 653B Bear and Compressing
- 【GOF23设计模式】_观察者模式
- django UnicodeEncodeError
- django cache 设置
- Google Gson 使用简介
- Zookeeper全解析——Paxos作为灵魂
- uva11090Going in Cycle!!(最短路spfa)
- Django 自带comment评论库使用
- tinyos-2.1.1目录结构解析
- Django Ajax CSRF 认证
- Go语言中的错误处理系统