【Question】
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] ]杨辉三角的特点是:
每i行有i个点,第一个和最后一个点为1,中间第j点为上一行j-1点+j点的和
vector<vector<int>> generate(int numRows) {
vector<vector<int>> tri;
if (numRows==0) return tri;
vector<int> vec;
vec.push_back(1);
tri.push_back(vec);
if (numRows==1) return tri;
for(int i=1;i<=numRows-1;i++)
{
vector<int> temp(NULL);
int j=0;
if (j==0) {temp.push_back(1);j++;}
for(j=1;j<i;j++)
temp.push_back(tri[i-1][j-1]+tri[i-1][j]);
if (j==i) temp.push_back(1);
tri.push_back(temp);
}
return tri;
}