Answers for "get diameter of binary tree"

4

get diameter of binary tree

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)));
}
Posted by: Guest on August-18-2020

Browse Popular Code Answers by Language