Why there is a runtime error in this code


  • 0
    Y

    '''class Solution {
    public:
    vector<vector<int>> generate(int numRows) {
    vector<vector<int>> triangle;
    for (int i = 0; i < numRows; i++)
    {
    vector <int> col;
    triangle.push_back(col);
    }
    triangle[0].push_back(1);
    if (numRows == 1)
    return triangle;
    else {
    triangle[1].push_back(1);
    triangle[1].push_back(1);
    if (numRows == 2)
    return triangle;
    else {
    for (int i = 2; i < numRows; i++) // nrows >= 3
    {
    triangle[i].push_back(1);
    for (int j = 1; j < i; j++)
    triangle[i].push_back(triangle[i - 1][j - 1] + triangle[i - 1][j]);
    triangle[i].push_back(1);
    }
    return triangle;
    }
    }
    }
    };
    '''
    Runtime Error Message: reference binding to null pointer of type 'struct value_type'
    But in my Visual Studio, it can run and get the result;
    Please give me some advice;


Log in to reply
 

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