杨辉三角
vector<vector<int>> generate(int numRows) {
// write code here
vector<vector<int>>vecall;
if (numRows == 0)
return vecall;
if (numRows == 1) {
vector<int>vec = vector<int>(1, 1);
vecall.push_back(vec);
return vecall;
}
if (numRows == 2) {
vector<int>vec = vector<int>(1, 1);
vector<int>vec1 = vector<int>(2, 1);
vecall.push_back(vec);
vecall.push_back(vec1);
return vecall;
}
vector<int>vec = vector<int>(1, 1);
vector<int>vec1 = vector<int>(2, 1);
vecall.push_back(vec);
vecall.push_back(vec1);
for (int i = 3; i <= numRows; i++) {
vector<int>vec = vector<int>(i, 1);
for (int j = 1; j <= i-2; j++) {
vec[j] = vecall[i - 2][j - 1] + vecall[i - 2][j];
}
vecall.push_back(vec);
}
return vecall;
}
//显示打印结果
void show(vector<vector<int>>& vecall) {
for (int i = 0; i < vecall.size(); i++)
{
for (int j = 0; j < vecall[i].size(); j++)
{
cout << vecall[i][j] << " ";
}
cout << endl;
}
}