This depends on your processing requirements: do you have complexity limits, or is the goal to have working, maintainable code by lunch time?
If it's the latter, take the simple approach:
- Locate both nodes in the tree.
- Starting at the first node, traverse back to the root, summing the path cost as you go, maintaining the partial sum at each node.
- Starting at the second node, also traverse-and-sum (full sum only, no partials) toward the root.
- When you encounter a node that's an ancestor of the first one, you've found the LCA.
- Add your current sum to the first node's partial sum for the LCA. Done.
This algorithm is easily understood by a first-term data structures student. With the consistent check for LCA, it's O(log(n)^2) -- not bad, but not the optimum of linear pre-work and constant-time query return for LCA.
If you need a faster algorithm, then I suggest that you augment the LCA pre-work algorithm so that each node also computes a hashed list (e.g. Python dictionary) of partial sums to each of its ancestors. Once you've done that, you have a constant-time computation for the LCA, and a constant-time look-up for each partial sum.