Python | DFS | No Global Variable
for each node, we want his left and right subtree sum, number of nodes in that subtree, and number of "good" nodes in that subtree. once we have that informatio
for each node, we want his left and right subtree sum, number of nodes in that subtree, and number of "good" nodes in that subtree. once we have that information, we can calculate the result for the root and simply return it.\nour result is the sum of good nodes on left, good nodes on right, and +1 if the current node is also a good node.\n```\n# Definition for a binary tree node.\n# class TreeNode:\n#     def __init__(self, val=0, left=None, right=None):\n#         self.val = val\n#         self.left = left\n#         self.right = right\nclass Solution:\n    def averageOfSubtree(self, root: Optional[TreeNode]) -> int:\n        def dfs(node): \n            if not node:\n                return 0, 0, 0\n            \n            #give me sum, count and num of good nodes in the subtree\n            ls, lc, rl = dfs(node.left) \n            rs, rc, rr = dfs(node.right)\n            \n            res = 0\n            if (ls + rs + node.val) // (lc + rc + 1) == node.val:\n                res += 1\n\t\t\t\t\n            return ls + rs + node.val, lc + rc + 1, res + rl + rr\n        return dfs(root)[2]\n```
['Depth-First Search', 'Python']