feat: 119_pascals_triagle_2
This commit is contained in:
parent
5c373dd7ef
commit
7933e840b3
21
119_pascals_triangle_2/main.cpp
Normal file
21
119_pascals_triangle_2/main.cpp
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#include <bits/stdc++.h>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
class Solution {
|
||||||
|
public:
|
||||||
|
vector<int> getRow(int rowIndex) {
|
||||||
|
vector<int> lastRow{1};
|
||||||
|
for (int i = 1; i < rowIndex + 1; i++) {
|
||||||
|
vector<int> currentRow(i + 1, 0);
|
||||||
|
currentRow[0] = 1;
|
||||||
|
currentRow[i] = 1;
|
||||||
|
|
||||||
|
for (int j = 1; j < i; j++) {
|
||||||
|
currentRow[j] = lastRow[j - 1] + lastRow[j];
|
||||||
|
}
|
||||||
|
|
||||||
|
lastRow = currentRow;
|
||||||
|
}
|
||||||
|
return lastRow;
|
||||||
|
}
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user