Diameter of a binary tree

PHOTO EMBED

Sun Jul 10 2022 10:07:22 GMT+0000 (Coordinated Universal Time)

Saved by @Ranjan_kumar #c++

class Solution {
  public:
  int height(Node* temp)
  {
      if(temp==NULL)
      return 0;
      int lh= height(temp->left);
      int rh=height(temp->right);
      
      return 1+max(lh,rh);
  }
    // Function to return the diameter of a Binary Tree.
    int diameter(Node* root) {
        if(root==NULL) return 0;
        int lh=height(root->left);
        int rh=height(root->right);
        
        int ld=diameter(root->left);
        int rd=diameter(root->right);
        
        return max(lh+rh+1,max(ld,rd));
        // Your code here
    }
};
content_copyCOPY

https://practice.geeksforgeeks.org/problems/diameter-of-binary-tree/1/