human
I am working on the file "03_BinaryTree_DivideConquer.ipynb".
The first task is:
Subtree with Maximum Average

https://www.lintcode.com/en/problem/subtree-with-maximum-average/
Can you write Python program for it?

Give me 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
"""
class Solution:
    # @param {TreeNode} root the root of binary tree
    # @return {TreeNode} the root of the maximum average of subtree
    
    node, average = None, -0x80000000          ## note this value!!
    
    def findSubtree2(self, root):
        # Write your code here
        self.helper(root)
        return self.node
        
        
    def helper(self, root):
        if not root:
            return 0, 0
            
        left_sum, left_size = self.helper(root.left)
        right_sum, right_size = self.helper(root.right)
        sum = left_sum + right_sum + root.val
        size = left_size + right_size + 1
        ave = sum*1.0 / size
        if ave >= self.average:
            self.average = ave
            self.node = root
        
        return sum, size

## instead of using minimun value!!

"""
Definition of TreeNode:
class TreeNode:
    def __init__(self, val):
        this.val = val
        this.left, this.right = None, None
"""
class Solution:
    # @param {TreeNode} root the root of binary tree
    # @return {TreeNode} the root of the maximum average of subtree
    
    node, average = None, 0
    
    def findSubtree2(self, root):
        # Write your code here
        self.helper(root)
        return self.node
        
        
    def helper(self, root):
        if not root:
            return 0, 0
            
        left_sum, left_size = self.helper(root.left)
        right_sum, right_size = self.helper(root.right)
        sum = left_sum + right_sum + root.val
        size = left_size + right_size + 1
        ave = sum*1.0 / size
        if self.node is None or ave >= self.average:
            self.average = ave
            self.node = root
        
        return sum, size