Diameter of Binary Tree Practice
vector<int>v;
int check(TreeNode* root)
{
if(root==NULL)
{
return 0;
}
int lh=check(root->left);
int rh=check(root->right);
v.push_back(lh+rh);
return 1+ max(lh,rh);
}
int diameterOfBinaryTree(TreeNode* root)
{
check(root);
int ans=*max_element(v.begin(),v.end());
return ans;
}