Simple solution Using Pair<int,int>
Code\n\nclass Solution {\npublic:\nint x=0;\n    pair<int,int> count(TreeNode* root){\n        if(root==NULL){return {0,0};}\n        pair<int,int> lans=count(r
# Code\n```\nclass Solution {\npublic:\nint x=0;\n    pair<int,int> count(TreeNode* root){\n        if(root==NULL){return {0,0};}\n        pair<int,int> lans=count(root->left);\n        pair<int,int> rans=count(root->right);\n        pair<int,int> ans;\n        ans.first=lans.first+rans.first+root->val;\n        ans.second=lans.second+rans.second+1;\n        if(ans.first/ans.second==root->val){x++;}\n        return ans;\n    }\n\n    int averageOfSubtree(TreeNode* root) {\n        count(root);\n        return x;\n    }\n};\n```
['Tree', 'Binary Tree', 'C++']