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] ]
分析:ret[i][j] = ret[i - 1][j] + ret[i - 1][j - 1]
class Solution {
vector<vector<int> > ret;
public:
vector<vector<int> > generate(int numRows) {
if(numRows == 0) return ret;
vector<int> item(1, 1);
ret.push_back(item);
for(int i = 1; i < numRows; i++) {
item.clear();
item.push_back(1); //第0个
for(int j = 1; j < i; j++) {
int tmp = ret[i - 1][j- 1] + ret[i - 1][j];
item.push_back(tmp);
}
item.push_back(1); //第n-1个
ret.push_back(item);
}
return ret;
}
};