Skip to content

Latest commit

 

History

History
24 lines (20 loc) · 532 Bytes

File metadata and controls

24 lines (20 loc) · 532 Bytes

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;
    }