弄个二维数组,每个数是它左上方和右上方的数的和
class Solution {
public:
vector<vector<int>> generate(int numRows) {
vector<vector<int>> ans(numRows);
for (int i = 0; i < numRows; i++) {
ans[i].resize(i + 1);
ans[i][0] = ans[i][i] = 1;
for (int j = 1; j < i; j++) {
ans[i][j] = ans[i - 1][j - 1] + ans[i - 1][j];
}
}
return ans;
}
};