A solution
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n *     int val;\n *     TreeNode *left;\n *     TreeNode *right;\n *     TreeNode() : val(0), left(nullptr), right(nullptr) {}\n *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n    void inOrder(TreeNode* list, int& res) {\n        if(list==nullptr) return;\n        inOrder(list->left, res);\n        int tempSum = 0;\n        int counter = 0;\n        mergerFun(list, res, tempSum, counter);\n        if((list->val) == tempSum/counter) res++;\n\n        inOrder(list->right, res);\n    }\n    void mergerFun(TreeNode* list, int& res, int& tempSum, int& counter) {\n        if(list==nullptr) return;\n        mergerFun(list->left, res, tempSum, counter);\n        \n        tempSum += list->val;\n        counter++;\n\n        mergerFun(list->right, res, tempSum, counter);\n    }\n    int averageOfSubtree(TreeNode* root) {\n        int res = 0;\n        inOrder(root, res);\n        return res;\n    }\n};\n```
['C++']