如果节点为空则返回长度为0
如果节点不为空,则长度+1 ,再+左/右子树中最长的长度
输入(节点)
int TreeDepth(TreeNode* pRoot)
{
if(pRoot==NULL)
return 0;
return 1+max(TreeDepth(pRoot->left),TreeDepth(pRoot->right));
}
如果节点为空则返回长度为0
如果节点不为空,则长度+1 ,再+左/右子树中最长的长度
输入(节点)
int TreeDepth(TreeNode* pRoot)
{
if(pRoot==NULL)
return 0;
return 1+max(TreeDepth(pRoot->left),TreeDepth(pRoot->right));
}

被折叠的 条评论
为什么被折叠?