mirror of
https://github.com/huihut/interview.git
synced 2024-03-22 13:10:48 +08:00
21 lines
577 B
C
21 lines
577 B
C
|
class Solution {
|
||
|
public:
|
||
|
vector<vector<int>> generate(int numRows) {
|
||
|
vector<vector<int>> triangle;
|
||
|
for(int i = 0; i < numRows; i++){
|
||
|
vector<int> v;
|
||
|
if(i==0){
|
||
|
v.push_back(1);
|
||
|
}
|
||
|
else{
|
||
|
v.push_back(1);
|
||
|
for(int j = 0; j < triangle[i-1].size()-1; j++){
|
||
|
v.push_back(triangle[i-1][j] + triangle[i-1][j+1]);
|
||
|
}
|
||
|
v.push_back(1);
|
||
|
}
|
||
|
triangle.push_back(v);
|
||
|
}
|
||
|
return triangle;
|
||
|
}
|
||
|
};
|