剑指offer之二叉树的高度

1 问题

求二叉树的深度,比如下面的二叉树,高度是4

               2

         2          1

   3      3     2    5

3

2 代码实现

int getTreeHeigh(Node *haed)
{
    if (head == NULLL)
    {
        return 0;
    }
    int left = getTreeHeigh(head->left);
    int right = getTreeHeigh(head->right);
    retur left > right ? (left + 1) : (right + 1);
}
(0)

相关推荐