My 5lines and 15ms c++ code


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

Log in to reply
 

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