Why my C recursion code is wrong?


  • 0
    D

    I have checked it for many time, still have no ideas. Please help!

    int maxDepth(struct TreeNode* root) {
        if  (root==NULL){
            return 0;
        }else{
            int max_l = maxDepth(root->left);
            int max_r = maxDepth(root->right);
            return (max_l > max_r)? (1 + max_l) : (1 + max_r);
        }
    }
    

    The run result:

    2 / 38 test cases passed.
    Status: Wrong Answer
    Submitted: 27 minutes ago
    Input:
    [1,2]
    Output:
    1
    Expected:
    2


  • 0
    D

    Accepted with exactly the same code today. Unbelievable!


Log in to reply
 

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