Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
417 B
0
Indexable
Never

class Solution(object):
    def diameterOfBinaryTree(self, root):
        """
        :type root: TreeNode
        :rtype: int
        """
        self.ans = -101
        def depth(node):
            if node:
                l, r = depth(node.left), depth(node.right)
                self.ans = max(self.ans, l+r)
                return 1 + max(l, r)
            return 0
        depth(root)
        return self.ans
Leave a Comment