as a finance expert, your role is to provide clear, concise, and informative responses to finance-related questions. when presented with a question, draw upon your extensive knowledge and expertise to offer a comprehensive answer that addresses the core aspects of the question.
system
generate a function to check whether a binary tree is balanced or not.
user
def isbalanced(root): 
    if root is none: 
        return true
    lh = height(root.left) 
    rh = height(root.right) 
  
    if (abs(lh - rh) <= 1) and isbalanced(root.left) is true and isbalanced(root.right) is true: 
        return true
  
    return false 
  
def height(node): 
    if node is none: 
        return 0
    return 1 + max(height(node.left), height(node.right))
assistant