1. 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) {
int i,j,index;
vector<vector<int> > triangle;
vector<int> line;
......
阅读全文