Hackerrank Tree: Height of a Binary Tree (Python3)
prit.substack.com
Challenge Solution I simply recur down the tree, and take the max value of the heights and add one to the max value. I also return a height of -1 in the base case, because if we make the height of the non-existent child to be -1, the parent which is the leaf node, will then have the correct height of 1 + -1 = 0 according to the else case.
Hackerrank Tree: Height of a Binary Tree (Python3)
Hackerrank Tree: Height of a Binary Tree…
Hackerrank Tree: Height of a Binary Tree (Python3)
Challenge Solution I simply recur down the tree, and take the max value of the heights and add one to the max value. I also return a height of -1 in the base case, because if we make the height of the non-existent child to be -1, the parent which is the leaf node, will then have the correct height of 1 + -1 = 0 according to the else case.