C++ Solution O(n) complexity , Easy solution : )
\n# O(n) Solution\n \n\n# Code\n\n\nclass Solution {\npublic:\n    pair<int,int> avgCount(TreeNode* root,int &count){\n        if(root==NULL){\n            retu
\n# $$O(n)$$ Solution\n \n\n# Code\n```\n\nclass Solution {\npublic:\n    pair<int,int> avgCount(TreeNode* root,int &count){\n        if(root==NULL){\n            return {0,0};\n        }\n        pair<int,int> lh = avgCount(root->left,count);\n        pair<int,int> rh= avgCount(root->right,count);\n\n        int sum = lh.first + rh.first + root->val ;\n        int ele = lh.second +rh.second + 1;\n\n        if(sum/ele==root->val) count++;\n        return {sum,ele};\n    }\n    int averageOfSubtree(TreeNode* root) {\n        int count = 0;\n        pair<int,int> cnt = avgCount(root,count);\n        return count;\n    }\n};\n```
['C++']