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> > ivv; if(numRows<=0) return ivv; else { for(int row=0; row<numRows; row++) { vector<int> iv; iv.push_back(1); for(int col=1; col<row; col++) { iv.push_back(ivv[row-1][col-1]+ivv[row-1][col]); } if(row>0) iv.push_back(1); ivv.push_back(iv); } return ivv; } } };