Why is this code running time error?


  • 0
    G
    class Solution {
    public:
        vector<vector<int>> generate(int numRows) {
            vector<vector<int>> res; 
            
            if (numRows <=0) {return res;}
            else {
           
                for (int i= 0; i<= numRows-1; i++) {
                    res[i][0] = 1;
                    
                    for (int j = 1;j < i; j++) {
                        res[i][j]=res[i-1][j-1]+res[i-1][j];
                    }
                    
                    res[i][i]=1;
                }
            
                return res;
            }
    
        }
    };

  • 0

    You're trying to access elements of a vector that doesn't have any.


Log in to reply
 

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