阅读背景:

二叉树的深度(递归和非递归)

来源:互联网 

给定一个二叉树,求此二叉树的深度。

递归方法:

int TreeDepth(TreeNode* pRoot)
{
	if (pRoot == NULL)
		return 0;
	if (pRoot->left == NULL && pRoot->right == NULL)
		return 1;
	return max(TreeDepth(pRoot->left), TreeDepth(pRoot->right)) + 1;
}int TreeDep



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: