Wrong Answer in Pascal Traingle


  • 0
    I
    class Solution {
    public:
        vector<vector<int> > generate(int numrows) {
            int mat[numrows][numrows];
       for(int i=0;i<numrows;i++)
        {
           for(int j=0;j<=i;j++)
             {
                if(j==0)
                 mat[i][j]=1;
                else
                 {
    
                   if(j==i)
                   mat[i][j]=1;
                   else
                   mat[i][j]=mat[i-1][j-1]+mat[i-1][j];
    
                 }
              cout<<mat[i][j]<<"\t";
    
             }//End for
              cout<<"\n";
         }//end for
        
        vector<vector<int> > result;
        for(int i=0;i<numrows;i++)
        {
            vector<int> ans;
            for(int j=0;j<=i;j++)
            {
                ans.push_back(mat[i][j]);
            }
            result.push_back(ans);
        }
            return result;
        }
    };`
    

    I am getting following wrong answer-
    Input: 1
    Output: 1
    Expected: [[1]]

    I am returning a vector so how this output is possible. I feel there is something wired in online judge.
    Please look at this issue..


Log in to reply
 

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