Lowest_Common_Ancestor_of_a_Binary_Tree

classSolution:
""" @param: root: The root of the binary search tree. @param: A: A TreeNode in a Binary. @param: B: A TreeNode in a Binary. @return: Return the least common ancestor(LCA) of the two nodes."""deflowestCommonAncestor(self, root, A, B):
# write your code hereif root isNone:
returnNoneif root == A or root == B:
return root
left =self.lowestCommonAncestor(root.left, A, B)
right =self.lowestCommonAncestor(root.right, A, B)
if left and right:
return root
if left:
return left
if right:
return right
returnNone