Trees and Graphs‎ > ‎

Binary Tree Height

Given a binary tree, write a function that returns its height.

int GetBinaryTreeHeight(Node *n)
{
    return GetBinaryTreeHeightHelper(n, 0);
}
 
int GetBinaryTreeHeightHelper(Node *nint h)
{
    if (nullptr == n)
        return h;
    h++;
 
    return max(GetBinaryTreeHeightHelper(n->left, h), GetBinaryTreeHeightHelper(n->right, h));
}