# Definition for a binary tree node.# class TreeNode:# def __init__(self, val=0, left=None, right=None):# self.val = val# self.left = left# self.right = rightclass Solution:def isBalanced(self, root: TreeNode) -> bool:return self.maxDepth(root) != -1def maxDepth(self, root):if root == None:return 0left = self.maxDepth(root.left)right = self.maxDepth(root.right)if left != -1 and right != -1 and abs(left-right) <= 1:return max(left, right) + 1else:return -1
