Public feed
#887938
public int height()
{
if (root == null)
return 0;
else if (root.getLeft() == null && root.getRight() == null)
return 1;
else
return countHeight(root);
}
private int countHeight(TreeNode n)
{
int right = 1;
int left = 1;
if (n.getLeft() == null && n.getRight() == null)
{
if (right>left)
return right;
else
return left;
}
else
{
if (n.getLeft() != null)
left += countHeight(n.getLeft());
if (n.getRight() != null)
right += countHeight(n.getRight());
}
if (right>left)
return right;
else
return left;
}