Why my solution can not pass while the java edition did


  • 0
    I

    [0,0,0,0,null,null,0,null,null,null,0] case wrong, but I passed it on the custom test
    why did this happen?

    /**

    • Definition for a binary tree node.
    • struct TreeNode {
    • int val;
      
    • struct TreeNode *left;
      
    • struct TreeNode *right;
      
    • };
      */

    int maxD=0;

    void search(struct TreeNode* root,int dp) {

    if (root==NULL) return ;
    
    if (dp>maxD) maxD=dp;
    
    search(root->left,dp+1);
    
    search(root->right,dp+1);
    

    }

    int maxDepth(struct TreeNode* root) {

    search(root,1);
    
    return maxD;
    

    }


  • 0
    H

    int maxDepth(struct TreeNode* root) {

    search(root,1);

    return maxD;
    }

    the maxD isn't defined in this function. So you should get a compiler error here.


Log in to reply
 

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