var lowestCommonAncestor = function(root, p, q) {
const isGreater = (p.val < root.val) && (q.val < root.val);
if (isGreater) return lowestCommonAncestor(root.left, p, q);
const isLess = (root.val < p.val) && (root.val < q.val);
if (isLess) return lowestCommonAncestor(root.right, p, q);
return root;
};
var lowestCommonAncestor = function(root, p, q) {
while (root !== null) {
const isGreater = (root.val < p.val) && (root.val < q.val)
if (isGreater) {
root = root.right;
continue;
}
const isLess = (p.val < root.val) && (q.val < root.val);;
if (isLess) {
root = root.left;
continue;
}
break;
}
return root;
};