Share My Accepted C++ Code


  • 0
    C

    int minDepth(TreeNode *root) {
    if (root == NULL) // leaf boundary
    return 0;
    if (root->right != NULL && root->left != NULL)
    return min(minDepth(root->right) + 1, minDepth(root->left) + 1);
    else if (root->right != NULL && root->left == NULL)
    return minDepth(root->right) + 1;
    else
    return minDepth(root->left) + 1;
    }


Log in to reply
 

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