118. Pascal's Triangle (Graph; WFS)
2015-10-04 15:27
447 查看
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(numRows, vector<int>()); if(numRows == 0) return result; result[0].push_back(1); for(int i =1; i < numRows; i++) //深度其次 { result[i].push_back(1); for(int j = 1; j<i;j++) //广度优先 { result[i].push_back(result[i-1][j-1]+result[i-1][j]); } result[i].push_back(1); } return result; } };
相关文章推荐
- Java中的static关键字解析
- http://www.bubuko.com/infodetail-425054.html try_to_wake_up()
- 地址解析和浏览器的百度地图和添加注释可以拖动
- LeetCode 38 Count and Say
- Material Design: NavigationView FlaotingActionBar SnackBar采用
- 杭电acm1098
- iOS开发-------自定义简单的表情键盘(UICollectionView 集合视图)
- Android 手机常用方法
- 现代C++
- 现代C++
- 程序员和代码
- 程序员和代码
- 20151004考试总结
- 127. Word Ladder (Tree, Queue; WFS)
- 点击按钮没反应,或者有时有反应有时没反应
- 66. Plus One | leetcode 66 Java 最短代码实现
- 【Violet3】【BZOJ2716】天使玩偶
- ISLR系列:(3)重采样方法 Cross-Validation & Bootstrap
- leetcode 289: Game of Life
- 计算文件夹大小