vault backup: 2022-06-28 09:31:37
This commit is contained in:
parent
07b823fb2d
commit
4f13b2d843
|
@ -56,7 +56,6 @@ Output: [[1]]
|
|||
Very simple and straightforward problem.
|
||||
> [!summary]
|
||||
> answer[i][j] = answer[i - 1][j - 1] + answer[i - 1][j]
|
||||
> except for special cases: i <= 1 etc.
|
||||
|
||||
I worked around special cases using the for loop in j: j = 1 and j < i.
|
||||
|
||||
|
@ -66,18 +65,16 @@ class Solution {
|
|||
public:
|
||||
vector<vector<int>> generate(int numRows) {
|
||||
vector<vector<int>> answer(numRows);
|
||||
int sum;
|
||||
// Initialize vector
|
||||
answer[0] = vector<int> (1);
|
||||
answer[0][0] = 1;
|
||||
for (int i = 1; i < numRows; i++) {
|
||||
// initialize sub vector
|
||||
answer[i] = vector<int> (i + 1);
|
||||
|
||||
for (int i = 0; i < numRows; i++) {
|
||||
// initialize sub-array
|
||||
answer[i] = vector<int>(i + 1);
|
||||
|
||||
answer[i][0] = 1;
|
||||
answer[i][i] = 1;
|
||||
for (int j = 1; j < i; j++) {
|
||||
answer[i][j] = answer[i - 1][j] + answer[i - 1][j - 1];
|
||||
}
|
||||
answer[i][i] = 1;
|
||||
}
|
||||
return answer;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue