Simple solution in c++


  • 0
    C

    class Solution {
    public:
    vector<vector<int>> generate(int numRows) {
    vector < vector<int>> a;
    for (int i = 0; i < numRows; i++)
    {
    vector<int>b(i+1,0);
    b[0]= b[i] = 1;
    int j = 1;
    while (i-j>0)
    {
    b[i - j] = a[i - 1][i-j] + a[i - 1][i -j-1];
    j++;
    }
    a.push_back(b);
    }
    return a;
    }
    };


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.