-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy path118
43 lines (37 loc) · 1.03 KB
/
118
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
class Solution {
public:
vector<vector<int>> generate(int numRows) {
vector<vector<int>> ans;
if(numRows==1){
vector<int>v(1,1);
ans.push_back(v);
return ans;
}
else if(numRows==2){
vector<int>v1(1,1);
ans.push_back(v1);
vector<int>v(2,1);
ans.push_back(v);
return ans;
}
else{
int k=numRows-2;
vector<int>v(1,1);
ans.push_back(v);
vector<int>v1(2,1);
ans.push_back(v1);
for(int i=2;i<numRows;i++){
vector<int> v3=ans[i-1];
vector<int> v4;
v4.push_back(v3[0]);
for(int j=0;j<v3.size()-1;j++){
v4.push_back(v3[j]+v3[j+1]);
}
v4.push_back(v3[v3.size()-1]);
ans.push_back(v4);
}
return ans;
}
// return ans;
}
};