class Solution {
public:
vector<int> getRow(int rowIndex) {
//注意0对应1个元素, 1对应2个元素, 。。。。。。
vector<int> upper;
upper.push_back(1);
if(rowIndex==0) {return upper;}
int times = 0;
while(times!=rowIndex) {
vector<int> temp;
vector<int>::iterator it = upper.begin();
temp.push_back(*it);
int value = *it;
it ++;
for( ; it != upper.end(); it++) {
temp.push_back(value+(*it));
value = *it;
}
temp.push_back(*upper.rbegin());
times ++;
upper.swap(temp);
}
return upper;
}
};
Pascal's Triangle II
最新推荐文章于 2020-05-20 13:31:00 发布