0ms simple C++ solution


  • 0
    J
    vector<vector<int>> generate(int numRows) {
        vector<vector<int>> result;
        if(numRows == 0)
            return result;
            
        for(int i = 0; i<numRows; i++) {
            vector<int> r(i + 1, 1);
            result.push_back(r);
            for(int j = 1; j<r.size() - 1; j++) 
                result[i][j] = result[i-1][j-1] + result[i-1][j];
        }
        
        return result;
    }

Log in to reply
 

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