Lowest Common Ancestor of a Binary Search Tree LeetCode solution in Python
1class Solution:2def lowestCommonAncestor(3self, root: "TreeNode", p: "TreeNode", q: "TreeNode"4) -> "TreeNode":56if ((root.val >= p.val) and (root.val <= q.val)) or (7(root.val >= q.val) and (root.val <= p.val)8):9return root10elif root.val > p.val:11return self.lowestCommonAncestor(root.left, p, q)12else:13return self.lowestCommonAncestor(root.right, p, q)