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] ]
class Solution {
public:
vector<vector<int> > generate(int numRows) {
vector<vector<int> > vvc;
if (numRows <= 0) return vvc;
vector<int> tmp;
tmp.push_back(1);
vvc.push_back(tmp);
if(numRows == 1 ) return vvc;
tmp.push_back(1);
vvc.push_back(tmp);
if(numRows == 2) return vvc;
for (int i = 2;i <numRows; i ++)
{
vector<int> tt = vvc[i-1];
vector<int> tp;
tp.push_back(1);
for (int j = 0;j < tt.size()-1;j ++)
{
tp.push_back(tt[j]+tt[j+1]);
}
tp.push_back(1);
vvc.push_back(tp);
}
return vvc;
}
};