1
# Definition for a binary tree node.3
def __init__(self, val=0, left=None, right=None):10
def isBalanced(self, root: TreeNode) -> bool:12
# Initialize the result to True15
# DFS through the tree19
# If there isn't a node, return previous depth23
# Check depths of the left and right subtrees24
left, right = dfs(node.left, i + 1), dfs(node.right, i + 1)26
# If they are more than 1 difference, save False to the result27
if abs(right - left) > 1:30
# Return the max depth of both subtrees31
return max(left, right)