forked from Nandinig24/Leetcode-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path119
52 lines (42 loc) · 1.21 KB
/
119
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
44
45
46
47
48
49
50
51
52
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;
vector<int> getRow(int rowIndex) {
vector<vector<int>> ans=generate(rowIndex+1);
vector<int> ans1=ans[ans.size()-1];
return ans1;
}
};