What is the mistake here? Failing a test case.


  • -1
    M

    int min = INT_MAX;
    void minLength (struct TreeNode *node, int prev)
    {
    if(node == NULL)
    {
    return;
    }

    prev++;
    
    if(node->left == NULL && node->right == NULL )
    {
        if(prev < min)
        {
            min = prev;
        }
        return;
    }
    if(node->left)
        minLength(node->left, prev);
    if(node->right)        
        minLength(node->right, prev);
    

    }
    int minDepth(struct TreeNode* root) {

    if(root == NULL)
       return 0;
    

    minLength(root, 0);
    return min;

    }


Log in to reply
 

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