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) {
// IMPORTANT: Please reset any member data you declared, as
// the same Solution instance will be reused for each test case.
vector<int> row;
vector<vector<int> > result;
if(numRows <= 0)
return result;
row.push_back(1);
result.push_back(row);
for(int i=1; i< numRows; i++){
row.clear();
row.push_back(1);
for(int k=0; k<result[i-1].size()-1; k++){
int x = result[i-1][k] + result[i-1][k+1];
row.push_back(x);
}
row.push_back(1);
result.push_back(row);
}
return result;
}
};