Fairly easy 0ms C++ solution


  • 0
    T
    vector<vector<int>> generate(int numRows) {
        std::vector<std::vector<int>> ret; 
        if(numRows == 0) 
            return ret; 
        
        ret.push_back({1});
        for(auto i = 1; i < numRows; ++i) {
            ret.push_back(std::vector<int>(i+1, 1)); 
                for(auto j = 1; j < i/2 + 1; ++j) {
                    ret[i][j] = ret[i][i-j] = ret[i-1][j-1] + ret[i-1][j]; 
                } 
        }
        return ret;
    }

Log in to reply
 

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