已经有一段时间没有学生时代了。在一家医院找到了一份IT专家的工作。现在我正试着去做一些实际的编程。我现在正在研究二叉树,我想知道确定树是否高度平衡的最好方法是什么。
我一直在想这样的事情:
public boolean isBalanced(Node root){
if(root==null){
return true; //tree is empty
}
else{
int lh = root.left.height();
int rh = root.right.height();
if(lh - rh > 1 || rh - lh > 1){
return false;
}
}
return true;
}
这是一个好的实现吗?还是我错过了什么?
https://stackoverflow.com/questions/742844
复制相似问题