【发布时间】:2019-05-18 23:30:24
【问题描述】:
谁能检查下面的高度代码是否正确?我不确定是否可以使用递归,因为public int height() 没有传入任何参数。我假设空树的高度为 0。
public class BinaryTree {
private class Node {
String value;
Node left;
Node right
}
Node root;
// Assume there is a constructor and various methods here
public int height() {
if (Node == null) {
return 0;
}
return 1 + math.max(left.height(), right.height());
}
}
【问题讨论】:
标签: java recursion binary iteration binary-tree