119. Pascal's Triangle II

来源:互联网 发布:电路图软件下载 编辑:程序博客网 时间:2024/06/14 10:58

Given an index k, return the kth row of the Pascal's triangle.

For example, given k = 3,

Return [1,3,3,1].

class Solution 

{
public:
    vector<int> getRow(int rowIndex)
    {

     vector<int> last(1,1);

      vector<int> ret;

      if(rowIndex<0)

      return ret;

      if(rowIndex==0)

      return last;

      for(int i=1;i<=rowIndex;i++)

        {

               last.push_back(0);

               ret=last;

              for(int j=1;j<=i;j++)

                 {

                     ret[j]=last[j]+last[j-1];

                  }

               last=ret;

               

        }

             return ret;

    }

};

原创粉丝点击