Simple C++ Solution
\nclass Solution {\nprivate:\n    int noOfNodes(TreeNode* node){\n        if(node == NULL){\n            return 0;\n        }\n        \n        return 1 + noOf
```\nclass Solution {\nprivate:\n    int noOfNodes(TreeNode* node){\n        if(node == NULL){\n            return 0;\n        }\n        \n        return 1 + noOfNodes(node -> left) + noOfNodes(node -> right);\n    }\n    \n    int pathsum(TreeNode* node){\n        if(node == NULL){\n            return 0;\n        }\n        int lh = pathsum(node -> left);\n        int rh = pathsum(node -> right);\n        \n        return (node -> val) + (lh+rh);\n    }\n    \n    void solve(TreeNode* &node, int &sum){\n        \n        if(node == NULL) return;\n        \n        if(pathsum(node) / noOfNodes(node) == (node -> val)){\n            cout<<node -> val << " ";\n            sum++;\n        }\n        \n        solve(node -> left, sum);\n        solve(node -> right, sum);\n        \n    }\npublic:\n    int averageOfSubtree(TreeNode* root) {\n        \n        int sum = 0;\n        solve(root, sum);\n        return sum;\n        \n    }\n};\n\n```
['Recursion']