Pascal's Triangle II

来源:互联网 发布:移动销售软件 编辑:程序博客网 时间:2024/06/10 12:46
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;    }};

0 0
原创粉丝点击