current
to the root of the BST.current
is not null:
a. Compare the values of p
and q
with the value of current
.
b. If both p
and q
are greater than current
, move current
to its right child.
c. If both p
and q
are less than current
, move current
to its left child.
d. If the values of p
and q
are on opposite sides of current
, or one of them equals current
, then current
is the LCA. Return current
.