Return the height if the binary tree is balanced, -1 otherwise.

    :param root: Root node of the binary tree.
    :type root: binarytree.Node | None
    :return: Height if the binary tree is balanced, -1 otherwise.
    :rtype: int
436761
def _is_balanced(root):
    
    if root is None:
        return 0
    left = _is_balanced(root.left)
    if left < 0:
        return -1
    right = _is_balanced(root.right)
    if right < 0:
        return -1
    return -1 if abs(left - right) > 1 else max(left, right) + 1
617140
def get_root( self, **kwargs ):
        ''' 
        '''
        if self.parent == None:
            return self
        else:
            return self.parent.get_root( **kwargs )
768960
public int maximumFringeImbalance()
    {
        int maxBal;
        GBSNode q = root();
        if (q.leftChild() == null)
        {
            maxBal = kFactor() - 1;
            if (maxBal < 3)
                maxBal = 3;
        }
        else
        {
            if ((kFactor() % 3) == 0)
                maxBal = kFactor() + 2;
            else
                maxBal = kFactor() + 1;
        }
        return maxBal;
    }
1156417
function parentise(tree, height) {
	if (height == tree.height) {
		return tree;
	} else {
		var list = [parentise(tree, height - 1)];
		list.height = height;
		list.sizes = [length(tree)];
		return list;
	}
}
980276
def avl_split_first(root):
    
    if root is None:
        raise IndexError('Empty tree has no maximum element')
    root, left, right = avl_release_kids(root)
    if left is None:
        new_root, first_node = right, root
    else:
        new_left, first_node = avl_split_first(left)
        new_root = avl_join(new_left, right, root)
    return (new_root, first_node)
560019
@Override
  protected int computeHeight() {
    N node = getRoot();
    int height = 1;

    // compute height
    while(!node.isLeaf() && node.getNumEntries() != 0) {
      E entry = node.getEntry(0);
      node = getNode(entry);
      height++;
    }
    return height;
  }
1172730
def readNodeByTree(self, start, height=None):
        
        pos = self.getNodePosition(start, height)
        return self.readNode(pos)
26737
def bin_tree_to_list(root):
    
    if not root:
        return root
    root = bin_tree_to_list_util(root)
    while root.left:
        root = root.left
    return root
866164
def get(tree, name):
    
    if name in tree:
        value = tree[name]
    else:
        return float("nan")
    try:
        a = float(value)
    except ValueError:
        a = float("nan")
    return a
807099
function balanceFactor(node) {
		return (node.left ? node.left.height : 0) - (node.right ? node.right.height : 0);
	}
358390
def root (path, root):
    
    if os.path.isabs (path):
        return path
    else:
        return os.path.join (root, path)
1262509
def height(cls, path):
        
        if os.path.exists( path ):
            sb = os.stat( path )
            h = (sb.st_size / BLOCK_HEADER_SIZE) - 1
            return h
        else:
            return None
580499
def remodelTreeRemovingRoot(root, node):
    
    import bioio
    assert root.traversalID.mid != node
    hash = {}
    def fn(bT):
        if bT.traversalID.mid == node:
            assert bT.internal == False
            return [ bT ]
        elif bT.internal:
            i = fn(bT.left)
            if i is None:
                i = fn(bT.right)
            if i is not None:
                hash[i[-1]]= bT
                i.append(bT)
            return  i
        return None
    l = fn(root)
    def fn2(i, j):
        if i.left == j:
            return i.right
        assert i.right == j
        return i.left
    def fn3(bT):
        if hash[bT] == root:
            s = '(' + bioio.printBinaryTree(fn2(hash[bT], bT), bT, True)[:-1] + ')'
        else:
            s = '(' + bioio.printBinaryTree(fn2(hash[bT], bT), bT, True)[:-1] + ',' + fn3(hash[bT]) + ')'
        return s + ":" + str(bT.distance)
    s = fn3(l[0]) + ';'
    t = bioio.newickTreeParser(s)
    return t
294205
def get_tree_depth( self ):
        '''  '''
        if (self.children):
            depth = 1
            childDepths = []
            for child in self.children:
                childDepths.append( child.get_tree_depth() )
            return depth + max(childDepths)
        else:
            return 0
419464
private int countInstances(HeaderElement root) {
        int count = 0;
        HeaderElement elem = root;
        while (null != elem) {
            if (!elem.wasRemoved()) {
                count++;
            }
            elem = elem.nextInstance;
        }
        return count;
    }
237223
def longest_consecutive(root):
    
    if root is None:
        return 0
    max_len = 0
    dfs(root, 0, root.val, max_len)
    return max_len
443637
function heightInorder(n, x) {
  if(n <= 0) {
    return 0
  }
  var r = rootInorder(n)
  if(x > r) {
    return heightInorder(n-r-1, x-r-1)
  } else if(x === r) {
    return bits.log2(n)
  }
  return heightInorder(r, x)
}