题目链接
Given numRows, generate the first numRows of Pascal's triangle.
For example, given numRows = 5,
Return as:
解题思路
TODO (稍后补充)
解答代码
class Solution {
public:
vector<vector<int>> generate(int numRows) {
vector<vector<int> > op;
if (numRows == 0) return op;
vector<int> line(numRows, 0);
line[0]=1;
op.push_back(vector<int>(1,1));
for (int i=1;i<numRows;i++) {
for (int k=i;k>=1;k--) {
line[k] = line[k] + line[k-1];
}
op.push_back(vector<int>(line.begin(), line.begin()+i+1));
}
return op;
}
};