Open ghost opened 8 years ago
Hi McFlurriez,
I think; the code is complex because of; when both nodes are found in left sub tree; the code will avoid traversing the right sub tree. This is not the case in your solution.
Thanks, Kanagavelu Sugumar.
This is true. Perhaps there should be a note about different solutions in the next revision, as is the case with many solutions in the book?
Hey all,
I noticed that the LowestCommonAncestorNoParent solution is a little more complex than it needs to be. The creation of a custom class to return values seems a little over the top, no?
What about this well known solution?
Pseudocode If root null, return null if root is one of the nodes, return root recursively call lca on left and right if both left and right not null, return root if one of left and right is not null, return the non null node
Code