Since you are writing Java, it is not necessary to pass parameters explicitly: you get one parameter "for free" - namely, the target object of the method call.
For that to work, the height()
method needs to be defined on the tree node object. Now the method definition is simple: in order for your Node
object to know its height()
, it needs to return either
- the larger of the heights of your left and and your right subtrees, plus one for the node itself, or
- one if both the left and the right subtrees are
null
.