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>> res; vector<int> curr; if(numRows<1)return res; if(numRows==1) { curr.push_back(1); res.push_back(curr); return res; } if(numRows==2) { curr.push_back(1); res.push_back(curr); curr.push_back(1); res.push_back(curr); return res; } curr.push_back(1); res.push_back(curr); curr.push_back(1); res.push_back(curr); curr.clear(); for(int i=2;i<numRows;i++) { curr.resize(i+1); for(int j=0;j<=i;j++) { if(j==0||j==i)curr[j]=1; else { curr[j]=res[i-1][j-1]+res[i-1][j]; } } res.push_back(curr); curr.clear(); } return res; } };