Are my recursion conditions right to compute binary tree height?

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

    Looks fine to me, although I'd personally change the last bit to:

    return Math.max(heightLeft, heightRight) + 1;
    

    I'm concerned that you can't run it at all though... why can you not write unit tests around this? I'd be nervous of any code I can't test :)

提交回复
热议问题