Python and don't know complexity though


  • 0
    S
    class Solution(object):
        def isBalanced(self, root):
            """
            :type root: TreeNode
            :rtype: bool
            """
            self.dif = []
            def depth(node):
                if not node:
                    return 0
                left, right = depth(node.left), depth(node.right)
                self.dif.append(abs(left-right))
                return 1 + max(left, right)
            depth(root)
            for dif in self.dif:
                if dif > 1:
                    return False
            return True

Log in to reply
 

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