119. Pascal's Triangle II

来源:互联网 发布:2016网络电影排行榜 编辑:程序博客网 时间:2024/06/06 01:41

class Solution {
public:
vector getRow(int rowIndex) {
if(rowIndex==0)
{
vector temp(1,1);
return temp;
}
else if(rowIndex==1)
{
vector temp(2,1);
return temp;
}
else
{
vector last(2,1);
vector cur;
for(int i=2;i<=rowIndex;i++)
{
cur.clear();
for(int j=0;j<=i;j++)
{
if(j==0)
cur.push_back(1);
else if(j==i)
cur.push_back(1);
else
cur.push_back(last[j-1]+last[j]);

            }            last.clear();            last.insert(last.begin(),cur.begin(),cur.end());        }        return cur;    }}

};

0 0