Tree: Depth-First Search - Balanced Binary Tree
Given this binary tree:
5 / \ 3 8 / \ 1 4and the following recursive function to check balance:
def check(node):
if not node:
return 0
left = check(node.left)
if left == -1:
return -1
right = check(node.right)
if right == -1:
return -1
if abs(left - right) > 1:
return -1
return max(left, right) + 1
What does check(root) return for this tree?