# Determining if binary tree is height balanced.

I've been working on this method to determine if a binary tree is height balanced.  It doesn't work correctly.  Can you look at it and guide me in the right direction?  Thanks.

p.s. I'm using height() method which returns the height at a given node.
``````public boolean heightBalanced(BinaryTree<T> tree){
if(tree==null){
return true;  //tree is empty
}
else if(tree.left!=null && tree.right!=null){
int lh = tree.height(tree.left);
int rh = tree.height(tree.right);
if(lh - rh > 1 || rh - lh > 1){
return false;
}
tree.heightBalanced(tree.left);
tree.heightBalanced(tree.right);
}
return true;
}
``````
LVL 1
###### Who is Participating?

Commented:
>                        tree.heightBalanced(tree.left);
>                        tree.heightBalanced(tree.right);

looks like that shpuld be:

return tree.heightBalanced(tree.left) &&
tree.heightBalanced(tree.right);

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.