0ms C++ DP straight forward


  • 0
    C
        vector<vector<int>> generate(int numRows) {
    
        vector<vector<int>> result;
        if(numRows==0) return result;
        if(numRows>=1) {
            vector<int> result_(1,1);
            result.insert(result.begin(),result_);
        }
        for(int i=1;i<numRows;i++){
            vector<int> result_;
            vector<int> lastrow(result[i-1].begin(),result[i-1].end());
            for(int j=0;j<=i;j++){
                if(j==0||j==i)
                result_.insert(result_.begin()+j,1);
                else
                result_.insert(result_.begin()+j,lastrow[j-1]+lastrow[j]);
            }
            result.insert(result.begin()+i,result_);
        }
        return result;
    }

Log in to reply
 

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