Given a BST, find the lowest common ancestor (LCA) of two given nodes p and q. LCA is defined as the lowest node that has both p and q as descendants.
Exploit BST property: if both p and q are less than root, LCA is in left subtree. If both greater, in right subtree. Otherwise, root is the LCA.
- While root != null:
- If both p.val < root.val and q.val < root.val: go left.
- Else if both > root.val: go right.
- Else: return root (it is the split point).
- Time Complexity: O(H)
- Space Complexity: O(1)