C++ RUN got correct answer submit get different wrong answer..


  • 0
    Z

    class Solution {
    public:
    vector<vector<int>> generate(int numRows) {
    vector<vector<int>> out;

        for(int i=0; i<numRows; i++){
            vector<int> in;
            if(i==0)
              in.push_back(1);
            else
            {
                for(int j=0; j<i+1; j++)
                {
                    if(j==0)
                    {
                        in.push_back(out[i-1][j]);
                    }
                    else{
                    in.push_back(out[i-1][j]+out[i-1][j-1]);
                    }
                }
            }
            out.push_back(in);
        }
        return out;
    }
    

    };


Log in to reply
 

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