Decorated Python
Using a decorator that turns a function evaluating a single node into a function that sums that evaluation over the whole subtree, and uses caching for overall 
Using a decorator that turns a function evaluating a single node into a function that sums that evaluation over the whole subtree, and uses caching for overall O(n) time.\n```\ndef subtree(f):\n    @cache\n    def g(root):\n        return f(root) + g(root.left) + g(root.right) if root else 0\n    return g\n\nclass Solution:\n    def averageOfSubtree(self, root: Optional[TreeNode]) -> int:\n\n        @subtree\n        def sum(root):\n            return root.val\n\n        @subtree\n        def number(root):\n            return 1\n\n        @subtree\n        def equals_average(root):\n            return root.val == sum(root) // number(root)\n        \n        return equals_average(root)\n```
['Python']