118. pascal’s triangle

Given numRows, generate the first numRows of Pascal’s triangle.

For example, given numRows = 5,
Return

1
2
3
4
5
6
7
[
[1],
[1,1],
[1,2,1],
[1,3,3,1],
[1,4,6,4,1]
]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class Solution {
public:
vector<vector<int>> generate(int numRows) {
vector<vector<int>> result;

if (numRows != 0) {
for (int i = 0; i < numRows; i++) {
vector<int> nums;
for (int j = 0; j <= i; j++) {
if (j == 0 or j == i)
nums.push_back(1);
else
nums.push_back(result[i - 1][j - 1] + result[i - 1][j]);
}
result.push_back(nums);
}
}
return result;
}
};