# Definition for a binary tree node.# class TreeNode:# def __init__(self, x):# self.val = x# self.left = None# self.right = NoneclassSolution:defisBalanced(self,root: TreeNode) ->bool:defdfs(node):if node isNone:return0 left =dfs(node.left) right =dfs(node.right)if left ==-1or right ==-1:return-1ifabs(left - right)>1:return-1returnmax(left, right)+1returnTrueifdfs(root)!=-1elseFalse