119. Pascal's Triangle II
Input: 3
Output: [1,3,3,1]vector<int> getRow(int rowIndex) { // time: O(n^2); space: O(n)
vector<int> res(rowIndex + 1, 1);
for (int i = 2; i <= rowIndex; ++i) {
for (int j = i - 1; j >= 1; --j) {
res[j] += res[j - 1];
}
}
return res;
}Last updated
