问题描述:
Write a function to check if a binary tree is balanced or not.

测试用例:
['assert is_tree_balanced(root) == False', 'assert is_tree_balanced(root1) == True', 'assert is_tree_balanced(root2) == False ']

生成的代码:
class TreeNode:
    def __init__(self, value):
        self.value = value
        self.left = None
        self.right = None

def check_height(node):
    if not node:
        return 0
    
    left_height = check_height(node.left)
    if left_height == -1:
        return -1
    
    right_height = check_height(node.right)
    if right_height == -1:
        return -1
    
    if abs(left_height - right_height) > 1:
        return -1
    
    return max(left_height, right_height) + 1

def is_tree_balanced(root):
    return check_height(root) != -1