My slowish python solution


  • 0
    D
      def depth(self,root):
            if root == None:
                return 0
            else:
                return max(self.depth(root.left), self.depth(root.right))+1
    
        
        
        def isBalanced(self, root):
            if root == None:
                return True
            n1=self.depth(root.left)
            n2=self.depth(root.right)
            if ((n1-n2) in range(-1,2)) and self.isBalanced(root.left) and self.isBalanced(root.right):
                return True
            else:
                return False

Log in to reply
 

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