class Solution {
public:
vector<int> getRow(int rowIndex) {
if(rowIndex == 0){
vector<int> ret;
ret.push_back(1);
return ret;
}
if(rowIndex == 1){
vector<int>ret;
ret.push_back(1);
ret.push_back(1);
return ret;
}
vector<vector<int> >vecint;
vecint.resize(2);
vecint[0].resize(1);
vecint[1].resize(2);
vecint[0][0] = 1;
vecint[1][0] = 1;
vecint[1][1] = 1;
int t = 0;
for(int i = 2; i <= rowIndex; ++i){
vecint[t].resize(i+1);
//head and tail does not conform to the principle
vecint[t][0] = 1;
vecint[t][i] = 1;
for(int j = 1; j < i; ++j){
vecint[t][j] = vecint[1-t][j-1] + vecint[1-t][j];
}
t = 1 - t;
}
return vecint[1-t];
}
};
leetcode Pascal's Palindrome 2
最新推荐文章于 2021-02-12 13:11:26 发布