【发布时间】:2013-11-22 01:42:03
【问题描述】:
找到二叉树最大深度的递归机制非常简单,但是我们如何在没有递归的情况下有效地做到这一点,因为我有大树,我宁愿避免这种递归。
//Recursive mechanism which I want to replace with non-recursive
private static int maxDepth(Node node) {
if (node == null) return 0;
return 1 + Math.max(maxDepth(node.left), maxDepth(node.right));
}
PS:我正在用 Java 寻找答案。
【问题讨论】:
标签: java algorithm recursion binary-tree