pascal’s triangle

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]
]
vector<vector<int> > generate(int numRows) {
vector<vector<int> >res;
if(numRows == 0) return res;
res.push_back(vector<int>(1,1));
for(int i=1; i < numRows; i++){
vector<int>temp;
for(int j=0; j<=i; j++){
if(j==0 || j==i) temp.push_back(1);
else{
temp.push_back(res[i-1][j-1]+res[i-1][j]);
}
}
res.push_back(temp);
}
return res;
}