Height of a binary tree

前端 未结 4 1930
庸人自扰
庸人自扰 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:17

    It's a recursive function. It's saying the height of a tree is 1 + the height of its tallest branch.

    Is BFS a breadth first search? I'm not sure what difference there would be in efficiency, but I like the simplicity of the recursive function.

提交回复
热议问题