一、题目
二、思路
三、代码
class Solution {
public:
vector<int> getRow(int rowIndex) {
vector<vector<int>>res(rowIndex+1);
for(int i=0;i<=rowIndex;++i){
res[i].resize(i+1);
res[i][0]=1;
res[i][i]=1;
for(int j=1;j<i;++j){
res[i][j]=res[i-1][j-1]+res[i-1][j];
}
}
return res[rowIndex];
}
};
class Solution {
public:
vector<int> getRow(int rowIndex) {
vector<int> row(rowIndex + 1);
row[0] = 1;
for (int i = 1; i <= rowIndex; ++i) {
for (int j = i; j > 0; --j) {
row[j] += row[j - 1];
}
}
return row;
}
};