Python: Simple Recursive Solution
Time Complexity: O(n) (We need to visit all n nodes)\nSpace Complexity: O(n) In the worst case the tree will look like a damn linked list and our recursion stac
**Time Complexity:** `O(n)` (We need to visit all n nodes)\n**Space Complexity:** `O(n)` In the worst case the tree will look like a damn linked list and our recursion stack will grow to n frames by the time we reach the leaf node.\n\n## Solution\n```\nclass Solution:\n    def averageOfSubtree(self, root: Optional[TreeNode]) -> int:\n        self.matchCount = 0\n        \n        self.explore(root)\n        \n        return self.matchCount\n    \n    def explore(self, root):\n        if root is None:\n            return 0, 0\n        \n        ls, lc = self.explore(root.left)\n        rs, rc = self.explore(root.right)\n        \n        childTotal = ls + rs + root.val\n        childCount = lc + rc + 1\n        \n        if childCount != 0 and root.val == childTotal // childCount:\n            self.matchCount += 1\n        \n        return childTotal, childCount\n\n```
['Recursion', 'Python']