1 問題
求二叉樹的深度,比如下面的二叉樹,高度是4
1. 2
2.
3. 2 1
4.
5. 3 3 2 5
6.
7. 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);
}