Python solution


  • 0
    W
    class Solution(object):
        def diameterOfBinaryTree(self, root):
            """
            :type root: TreeNode
            :rtype: int
            """
            def help(root):
                if not root:
                    return 0, 0
                lh, lm = help(root.left)
                rh, rm = help(root.right)
                return max(lh, rh) + 1, max(lm, rm, lh + rh)
            return help(root)[1]
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.