function lowestCommonAncestor(root, p, q):
if root is None:
return None
if root == p or root == q:
return root
left = lowestCommonAncestor(root.left, p, q)
right = lowestCommonAncestor(root.right, p, q)
if left and right:
return root
return left if left else right
time in the worst case (skewed tree visits every node). space for the recursion stack, where is the tree height.