-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlec_1.cpp
More file actions
26 lines (21 loc) · 729 Bytes
/
Copy pathlec_1.cpp
File metadata and controls
26 lines (21 loc) · 729 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
class Solution {
public:
vector<int> getRow(int n) {
vector<int> ansE(n + 1, 1); // Initialize with 1's, size n+1
long long ans = 1;
// Printing the rest of the part and filling ansE
for (int i = 1; i <= n / 2; i++) {
ans = ans * (n - i + 1) / i;
ansE[i] = ans; // Set the ith value
ansE[n - i] = ans; // Set the symmetric value
}
return ansE;
}
vector<vector<int>> generate(int numRows) {
vector<vector<int>>ansRow;
for(int i = 0 ;i<numRows;i++){
ansRow.push_back(getRow(i));
}
return ansRow;
}
};