Are my recursion conditions right to compute binary tree height?

后端 未结 4 1740
既然无缘
既然无缘 2021-01-28 19:59

I\'m trying to know whether my code is right or wrong with your help, because sadly I can\'t run it to check.

There are no compile errors. What I\'m trying to do is to

4条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-28 20:42

    In the code in the question, are we not getting height +1? the height is defined as 'length of the path from the root to the deepest node in the tree. A (rooted) tree with only one node (the root) has a depth of zero.'(wikipedia)

    if in question's code if give the root to a tree with just 1 node it will give height as 1, which should infact be 0..

    Please correct me if i am wrong somewhere..

提交回复
热议问题