Based on the fact that BST is ordered. and I simple use the fact of products with the root.

```
public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {
for(; ;) {
if((p.val - root.val) * (q.val - root.val) <= 0) return root;
if(p.val < root.val) root = root.left;
else root = root.right;
}
}
```