Are my recursion conditions right to compute binary tree height?

后端 未结 4 1743
既然无缘
既然无缘 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:22

    Really compact version:

    public int height(RBNode t) {
        if (t == null) {
            return 0;
        }
        return Math.max(height(t.left), height(t.right)) + 1;
    }
    

提交回复
热议问题