Intuitive Python solution using DFS (w/ explanation)
Using recursion, we check if the left subtree is balanced with the right subtree. If it is, the function returns the height of the combined subtree (max between
Using recursion, we check if the left subtree is balanced with the right subtree. If it is, the function returns the height of the combined subtree (max between left subtree height and right subtree height). If not, it returns -inf, so that every check involving that subtree fails.\n\n```\ndef isBalanced(self, root: TreeNode) -> bool:\n\tdef r_balanced(tree, height):\n\t\tif not tree:  # base case\n\t\t\treturn height\n\t\tl = r_balanced(tree.left, height+1)\n\t\tr = r_balanced(tree.right, height+1)\n\t\treturn max(l, r) if abs(l-r) <= 1 else -float("inf")\n\n\treturn r_balanced(root, 0) >= 0\n```
['Depth-First Search', 'Python']