C solution


  • 0
    B

    int minDepth(struct TreeNode* root) {
    if(!root)
    return 0;

    if(!root->left)    return (!root->right)?1:minDepth(root->right)+1;
    else if(!root->right)    return minDepth(root->left)+1;
    int lmin,rmin;
    return ((lmin=minDepth(root->left))<(rmin=minDepth(root->right)))?lmin+1:rmin+1;
    

    }


Log in to reply
 

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