int MaxDepth(Node n)
{
if (!n.left && !n.right)
return 1;
int l = 0;
if (n.left)
l = MaxDepth(n.left) + 1;
int r = 0;
if (n.right)
r = MaxDepth(n.right) + 1;
return Max(l, r);
}
link: http://www.cnblogs.com/mend/archive/2012/04/09/2439486.html
本文详细阐述了如何通过递归方法计算二叉树的最大深度,并提供了具体的实现代码。其中包括了判断节点是否存在左右子节点的条件,以及如何在递归过程中更新最大深度的逻辑。
420

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



