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.
c#csharpsolutionthatdoesn'tuserecursionprivatestaticintgetHeight(Noderoot){if(root==null){return-1;// height of empty tree is -1}Queue<Node>queue=newQueue<Node>();queue.Enqueue(root);intheight=-1;while(queue.Count>0){intnodeCount=queue.Count;// Number of nodes at the current levelheight++;// Process each node at the current levelwhile(nodeCount>0){Nodenode=queue.Dequeue();// Enqueue left and right children of the current nodeif(node.left!=null){queue.Enqueue(node.left);}if(node.right!=null){queue.Enqueue(node.right);}nodeCount--;}}returnheight;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Day 22: Binary Search Trees
You are viewing a single comment's thread. Return to all comments →