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]
]
1 class Solution { 2 public: 3 vector<vector<int> > generate(int numRows) { 4 vector<vector<int> > res(numRows); 5 for(int i = 0; i < numRows; i++) { 6 res[i].push_back(1); 7 for(int j = 1; j < i; j++) { 8 res[i].push_back(res[i-1][j-1] + res[i-1][j]); 9 } 10 if(i >= 1) res[i].push_back(1); 11 } 12 return res; 13 } 14 };