There are several ways to solve LCA. One approach converts the tree into an array using an Euler tour, then reduces LCA to a Range Minimum Query. I'll cover that technique later in this section.
For a single LCA query on a moderate tree, a simpler recursive approach works well. You recurse through both subtrees and combine results. If you find one target on each side, the current node is the LCA. This runs in time and space, and you can implement it in a few lines of code.