1 class Solution: 2 def lowestCommonAncestor(self, root: 'TreeNode', p: 'TreeNode', q: 'TreeNode') -> 'TreeNode': 3 if p.val < root.val and q.val < root.val: 4 return self.lowestCommonAncestor(root.left,p,q) 5 elif p.val > root.val and q.val > root.val: 6 return self.lowestCommonAncestor(root.right,p,q) 7 else:return root