Easiest solution by using Formula


#1
vector<vector<int> > Solution::solve(int n) {
    
    vector<vector<int>> m;  // 2d vector to store Pascal's triangle
    
    int C; // used to represent C(line, i)

    for (int line = 0; line < n; line++) // Traversing from 0th line to n-1 line
    {
        vector<int> v;
        for (int i = 0; i <= line; i++)
        {
            // 1st & last number will be 1 & rest will be as formula
            C = (i == 0 || line == i) ? 1 : C * (line - i + 1) / i;
            v.push_back(C);
        }
        m.push_back(v);
    }
    return m;
}