4-line clear C++ solution


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

Log in to reply
 

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