Pascal's Triangle II - Codeprg

Breaking

programing News Travel Computer Engineering Science Blogging Earning

Wednesday, 12 August 2020

Pascal's Triangle II

Pascal's Triangle II

Pascal's Triangle II

Given a non-negative index k where k ≤ 33, return the kth index row of the Pascal's triangle.

Note that the row index starts from 0.

class Solution {
public:
    vector<int> getRow(int row) {
        if(row==0) return {1};
        auto v=getRow(row-1);
        int n=v.size();
        for(int i=1;i<n;++i)
            v[i]=(i<=n/2)?(v[i]+v[n-i]):v[n-i];
        v.push_back(1);
        return v;
    }
};

 


class Solution {
public:
    vector<int> getRow(int row) {

 // vector<int> temp,v{1};
        // int j=1;
        // while(j<=row)
        // {
        //     temp.push_back(1);
        //   for(int i=0;i<v.size()-1;++i)
        //    temp.push_back(v[i]+v[i+1]);
        //      temp.push_back(1);
        //         v.clear();
        //         v=temp;
        //         temp.clear();
        //     ++j;
        // }
        // return v;

    }
};