blob: 343c1164e66ac3b1b15fb16b2fc3d34470cf5d47 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
#include "leetcode.h"
class Solution {
public:
vector<vector<int>> generate(int numRows) {
vector<vector<int>> ans(numRows);
for (int i = 0; i < numRows; i++) {
vector<int> row(i + 1, 1);
int mid = i >> 1;
for (int j = 1; j <= mid; j++) {
int val = ans[i - 1][j - 1] + ans[i - 1][j];
row[j] = val;
row[row.size() - j - 1] = val;
}
ans[i] = row;
}
return ans;
}
};
|