Given the root of a BST
root and two values p and q (both nodes exist in the tree). Return the value of the lowest common ancestor of nodes p and q.Example 1
Input: root = [6,2,8,0,4,7,9,null,null,3,5], p = 2, q = 4
Output: 2
Explanation: Both nodes in the left subtree, LCA is 2.
Output: 2
Explanation: Both nodes in the left subtree, LCA is 2.
Example 2
Input: root = [6,2,8,0,4,7,9,null,null,3,5], p = 2, q = 8
Output: 6
Explanation: LCA of nodes 2 and 8 is root 6.
Output: 6
Explanation: LCA of nodes 2 and 8 is root 6.