forked from shriyajalana/programming1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate.cpp
More file actions
29 lines (28 loc) · 713 Bytes
/
Copy pathgenerate.cpp
File metadata and controls
29 lines (28 loc) · 713 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
28
29
class Solution {
public:
vector<vector<int>> generate(int numRows) {
vector<vector<int>> ans;
vector<int> temp;
temp.push_back(1);
ans.push_back(temp);
if(numRows==1){
return ans;
}
temp.push_back(1);
ans.push_back(temp);
if(numRows==2){
return ans;
}
while(numRows-->2){
vector<int> current;
current.push_back(1);
for(int i=0;i<temp.size()-1;i++){
current.push_back(temp[i]+temp[i+1]);
}
current.push_back(1);
temp=current;
ans.push_back(current);
}
return ans;
}
};