Easy Approach using Pair & DFS || O(n)
\n\n# Code\n\n\nclass Solution {\npublic:\n    int ans=0;\n\n    pair<int,int>solve(TreeNode*root){\n        if(root==NULL)return {0,0};\n\n        pair<int,int
\n\n# Code\n```\n\nclass Solution {\npublic:\n    int ans=0;\n\n    pair<int,int>solve(TreeNode*root){\n        if(root==NULL)return {0,0};\n\n        pair<int,int>left=solve(root->left);\n        int left_sum=left.first;\n        int left_size=left.second;\n\n        pair<int,int>right=solve(root->right);\n        int right_sum=right.first;\n        int right_size=right.second;\n\n        int sum=left_sum+right_sum+root->val;\n        if(sum/(1+left_size+right_size)==root->val){\n            ans++;\n        }\n        return {sum,(1+left_size+right_size)};\n\n\n    }\n    int averageOfSubtree(TreeNode* root) {\n        solve(root);\n        return ans;\n        \n    }\n};\n```
['Depth-First Search', 'C++']