题目来源【Leetcode】
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>>tr(numRows);
for(int i = 0; i < numRows; i++){
tr[i].resize(i+1);
for(int j = 0; j < i+1; j++){
if(j == 0 || j == i) tr[i][j] = 1;
else tr[i][j] = tr[i-1][j-1]+tr[i-1][j];
}
}
return tr;
}
};