GivennumRows, generate the firstnumRowsof Pascal's triangle.
[
[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>> res;
for(int i = 0; i<numRows; i++){
if(i == 0) res.push_back(vector<int>(1,1));
else{
vector<int> t;
for(int j = 0; j<=i; j++){
if(j == 0 || j == i) t.push_back(1);
else t.push_back(res[i-1][j-1] + res[i-1][j]);
}
res.push_back(t);
}
}
return res;
}
};