feat: 119_pascals_triagle_2

This commit is contained in:
SquidSpirit 2025-03-14 23:36:46 +08:00
parent 5c373dd7ef
commit 7933e840b3

View 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;
}
};