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.
I prefer an iterative solution to this problem rather than recursive. The code is similarly brief, and there isn't any need to load up the call stack.
staticNodelca(Noderoot,intv1,intv2){Nodetemp=root;// not necessary, just use root, just a leftover from a different attempt.while(true){if(temp.data>v1&&temp.data>v2){temp=temp.left;}elseif(temp.data<v1&&temp.data<v2){temp=temp.right;}else{returntemp;}}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Binary Search Tree : Lowest Common Ancestor
You are viewing a single comment's thread. Return to all comments →
I prefer an iterative solution to this problem rather than recursive. The code is similarly brief, and there isn't any need to load up the call stack.