Runtime Error with Last executed input: [0,null,0,null,0,null,0,null,0,null,0,...0,0]


  • 0
    I
    int maxDepth(struct TreeNode* root) {
        if (root==NULL)
            return 0;
        else{
            int maxdep=1,i;
    	    struct TreeNode *path[1000];
    	    int ipath[1000];
    	    path[1] = root;
    	    ipath[1] = 1;
    	    i=1;
    	
    	    while ((i!=1)||ipath[1]<=2)	
    	    {
    	        if (ipath[i]==1)
    		    {
    			    if ((*path[i]).left!=NULL)
    			    {
    				    i++;
    				    path[i]=(*path[i-1]).left;
    				    ipath[i]=1;	
    			    }
    			    else
    			     {
    				     ipath[i]++;	
    			    }
    		    }		
    		    else if (ipath[i]==2)	
    		    {
    			    if ((*path[i]).right!=NULL)
    			    {
    				    i++;
    				    path[i]=(*path[i-1]).right;
    				    ipath[i]=1;		
    			    }
    			    else
    			    {
    				    if (i>maxdep)
    					    maxdep=i;
    				    ipath[i]++;
    			    }
    		    }
    		    else
    		    {
    			    i--;
    			    ipath[i]++;	
    		    }
    	    }
    	    return maxdep;
        }
    }

  • 0
    I

    The size of the array is not big enough.


Log in to reply
 

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