Find Distance in a Binary Tree
Record depths, mark the path from p to the root, then climb from q; the distance is depth(p) + depth(q) - 2 depth(LCA).
Record depths, mark the path from p to the root, then climb from q; the distance is depth(p) + depth(q) - 2 depth(LCA).