Ezvor

2773. Height of Special Binary Tree

MediumTree Preparing judge… LeetCode
TreeDepth-First SearchBreadth-First SearchBinary Tree

Hints

Hint 1
To solve the problem, we must first distinguish leaves from internal nodes.
Hint 2
For some node v, if v.left == null or v.right == null, then v is not a leaf.
Hint 3
If the previous condition does not hold, and v.left.right == v, then v is a leaf node.
Hint 4
Now that we can check if some node is a leaf, we can make the function “heightOfTree” a recursive function that returns the tree's height in which its input is the root of that subtree.