We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
That is not quite accurate - the height of the root node is 0. However for the reasons I outline in my post here you are right to point out that you must return -1 when you encounter a null node. You are guaranteed never to see null at the root of the tree.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Tree: Height of a Binary Tree
You are viewing a single comment's thread. Return to all comments →
That is not quite accurate - the height of the root node is
0
. However for the reasons I outline in my post here you are right to point out that you must return-1
when you encounter anull
node. You are guaranteed never to seenull
at the root of the tree.