📜  获取二叉树的直径 - 无论代码示例

📅  最后修改于: 2022-03-11 14:59:15.780000             🧑  作者: Mango

代码示例1
int getDiameter(TreeNode* root)
{
    if(root == NULL)
        return(0);
    int lheight = getHeight(root->left);
    int rheight = getHeight(root->right);
    
    int ldiameter = getDiameter(root->left);
    int rdiameter = getDiameter(root->right);
    
    return(max(lheight+rheight+1,max(ldiameter,rdiameter)));
}