human
I am working on the file "03_BinaryTree_DivideConquer.ipynb".
The first task is:
Lowest Common Ancestor III: Return null if LCA does not exist

https://www.lintcode.com/en/problem/lowest-common-ancestor-iii/
Can you write Python program for it?

=====
Can you provide a the Python program you requested?
assistant
#Here is the Python program you requested.

"""
Definition of TreeNode:
class TreeNode:
    def __init__(self, val):
        this.val = val
        this.left, this.right = None, None
"""
import copy
class Solution:
    """
    @param {TreeNode} root The root of the binary tree.
    @param {TreeNode} A and {TreeNode} B two nodes
    @return Return the LCA of the two nodes.
    """ 
    def lowestCommonAncestor3(self, root, A, B):
        # write your code here
        node, a, b = self.helper(root, A, B)
        return node
        
        
    def helper(self, root, A, B):
        if root is None:
            return None, False, False
            
        leftNode, leftA, leftB = self.helper(root.left, A, B)
        rightNode, rightA, rightB = self.helper(root.right, A, B)
        
        a = leftA or rightA or root == A
        b = leftB or rightB or root == B
        
        if not a or not b:
            return None, a, b
        elif leftNode:
            return leftNode, a, b
        elif rightNode:
            return rightNode, a, b
        else:
            return root, a, b