【发布时间】:2015-07-19 04:42:35
【问题描述】:
我尝试使用此逻辑执行此操作,但出现错误
public static void removeLeaves(BinaryTreeNode<Integer> root) {
BinaryTreeNode<Integer> temp = root;
if (root == null) {
return;
}
if (root.left == null && root.right == null) {
root = null;
}
removeLeaves(temp.left);
removeLeaves(temp.right);
}
整棵树按原样打印。请在不改变我的逻辑的情况下帮助我。
【问题讨论】:
-
如果逻辑有缺陷,如果不允许我们更改逻辑,就很难提出更正建议。只是想我会指出这一点,以防你的意思不同。
标签: java algorithm binary-tree