link->
https://practice.geeksforgeeks.org/problems/diameter-of-binary-tree/1#
my code->
int height(struct Node* root)
{
//code here
if(root==NULL)
{
return 0;
}
int h1=height(root->left);
int h2=height(root->right);
return 1+maxx(h1,h2);
}
int maxx(int x, int y)
{
if (x > y)
return x;
else
return y;
}
int diameter(struct Node* root) {
// code here
if(root==NULL)
{
return 0;
}
int h1=height(root->left);
int h2=height(root->right);
int op1=h1+h2;
int op2=diameter(root->left);
int op3=diameter(root->right);
return maxx(op1,maxx(op2,op3));
}