Python | DFS | Easy to Understand
```\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
```\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        result = 0\n\t\t\n        def traverse(node):\n            nonlocal result\n            \n            if not node:\n                return 0, 0\n            \n            left_sum, left_count = traverse(node.left)\n            right_sum, right_count = traverse(node.right)\n            \n            s = node.val + left_sum + right_sum\n            c = 1 + left_count + right_count\n            \n            if s // c == node.val:\n                result += 1\n            \n            return s, c\n        \n        traverse(root)\n        \n        return result\n            \n            \n
['Depth-First Search', 'Python', 'Python3']