The solution forgets to mention that both nodes are required to be present in the tree.
If it’s not the case then
- the program will return “would-be” LCA (for example, for non-existing nodes with key 12 and 14 the node H(13) is returned)
- NullPointerException is thrown (for example, for non-existing nodes with key 14 and 15)