-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathgetRow.cpp
More file actions
27 lines (25 loc) · 695 Bytes
/
Copy pathgetRow.cpp
File metadata and controls
27 lines (25 loc) · 695 Bytes
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
class Solution {
public:
vector<int> getRow(int rowIndex) {
int numRows=rowIndex+1;
vector<vector<int>> ans;
ans.push_back({1});
if(rowIndex==0){
return ans[rowIndex];
}
ans.push_back({1,1});
if(rowIndex==1){
return ans[rowIndex];
}
for(int i=0;i<numRows-2;i++){
vector<int> temp=ans[ans.size()-1];
vector<int> RealTemp={1};
for(int j=0;j<temp.size()-1;j++){
RealTemp.push_back(temp[j]+temp[j+1]);
}
RealTemp.push_back(1);
ans.push_back(RealTemp);
}
return ans[rowIndex];
}
};