0
如何推广用于查找二叉树到非二叉树高度的递归代码?我查了Non-binary tree height。但只是一个伪代码。到目前为止,我已经写了这是我拍摄的错误回答以下问题:计算非二叉树的高度
public static <MyType> int calculateHeight(MyTreeNode<MyType> r){
if (r ==null)
return -1;
if (r.children.size()==0)
return 0;
int count=0;
List<Integer> heights = new ArrayList<>();
for (MyTreeNode<MyType> e : r.children)
count = calculateHeight(e)+1;
heights.add(count);
return max(heights);
}
寻求调试帮助的问题必须不仅包括重现问题所需的最短代码,还包括期望的行为和特定的问题或错误。 _不工作_不是一个适当的问题描述。请阅读[如何调试小程序](http://ericlippert.com/2014/03/05/how-to-debug-small-programs/)。 – honk