[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"searchBlogPosts":3,"$fqScKr3uNLeBhAXPqpqiPrU2tPrxJ83SaUPWM73Pj4ms":7},[4],{"_path":5,"title":6},"\u002Fblog\u002F2023\u002F09\u002F17\u002Fspring-boot-postgresql","Spring Boot with PostgreSQL & pgAdmin in Docker",{"title":8,"category":9,"problemHtml":10,"solutions":11,"repoUrl":16},"Binary Tree Diameter","Data Structures & Algorithms","",[12],{"lang":13,"label":14,"html":15},"python","Python","\u003Cpre>\u003Ccode class=\"language-python\"># Definition for a binary tree node.\n# class TreeNode:\n#     def __init__(self, val=0, left=None, right=None):\n#         self.val = val\n#         self.left = left\n#         self.right = right\n\nclass Solution:\n    def diameterOfBinaryTree(self, root: Optional[TreeNode]) -&gt; int:\n        if not root: return 0\n\n        leftHeight = self.maxHeight(root.left)\n        rightHeight = self.maxHeight(root.right)\n\n        diameter = leftHeight + rightHeight\n\n        sub = max(self.diameterOfBinaryTree(root.left), self.diameterOfBinaryTree(root.right))\n\n        return max(diameter, sub)\n\n    \n    def maxHeight(self, root: Optional[TreeNode]) -&gt; int:\n        if not root:\n            return 0\n        \n        return 1 + max(self.maxHeight(root.left), self.maxHeight(root.right))\u003C\u002Fcode>\u003C\u002Fpre>","https:\u002F\u002Fgithub.com\u002Fvishwarajsali\u002FInterviewPrep\u002Ftree\u002Fmain\u002FData%20Structures%20%26%20Algorithms%2Fbinary-tree-diameter"]