Height of a binary tree

前端 未结 4 2093
庸人自扰
庸人自扰 2021-01-30 10:59

Consider the following code:

public int heightOfBinaryTree(Node node)
{
    if (node == null)
    {
        return 0;
    }
    else
    {
        return 1 +
            


        
4条回答
  •  逝去的感伤
    2021-01-30 11:28

    The height of a tree is the length of longest downward path from it's root. This function is a recursive way to count the levels of a binary tree. It just increments counters as it descends the tree, returning the maximum counter (the counter on the lowest node).

    I hope I have helped.

提交回复
热议问题