Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
414 B
1
Indexable
Never
class Solution(object):
    def isBalanced(self, root):
        """
        :type root: TreeNode
        :rtype: bool
        """
        self.ans = True
        def depth(node):
            if node:
                l, r = depth(node.left), depth(node.right)
                self.ans = self.ans and abs(l-r) <= 1
                return 1 + max(l, r)
            return 0
        depth(root)
        return self.ans
Leave a Comment