var lowestCommonAncestor = function (root, p, q) { if (!root) return null; let res = null; const rec = (root) => { if (root.val > p.val && root.val > q.val) { root.left && rec(root.left); } else if (root.val < p.val && root.val < q.val) { root.right && rec(root.right); } else { res = root; } }; rec(root); return res; };