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] ]
代码
class Solution {
public:
vector<vector<int> > generate(int numRows) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
vector<int> Row;
vector<vector<int> >Triangle;
int t = 0;
for(int i = 0;i < numRows;i++)
{
for(int j = 0;j <= i;j++)
{
if(j == 0||j == i)
Row.push_back(1);
else
{
t = Triangle[i-1][j-1] + Triangle[i-1][j];
Row.push_back(t);
}
}
Triangle.push_back(Row);
Row.clear();
}
return Triangle;
}
};