【发布时间】:2021-02-13 14:57:54
【问题描述】:
我正在尝试使用递归来获取二叉搜索树的所有非叶节点。我可以计算非叶节点,但是如何返回它们..?
int countNonLeafNodes(Node root)
{
if (root == null || (root.left == null &&
root.right == null))
return 0;
return 1 + countNonLeafNodes(root.left) +
countNonLeafNodes(root.right);
}
【问题讨论】:
标签: java recursion binary-tree