C++ || O(n) || Easy and fast
\n\n\nclass Solution {\n\npublic:\n\n    int ans =0;\n\t\n    pair solve(TreeNode root){\n\t\n        if(!root) return {0,0};\n\t\t\n        auto lh = solve(roo
\n\n\nclass Solution {\n\npublic:\n\n    int ans =0;\n\t\n    pair<int,int> solve(TreeNode* root){\n\t\n        if(!root) return {0,0};\n\t\t\n        auto lh = solve(root->left);\n        auto rh = solve(root->right);\n        \n        int sum = lh.first +  rh.first + root->val;\n        int n = lh.second + rh.second + 1;\n        \n        if(sum / n == root->val)ans++;\n        \n        return {sum,n};\n    }\n    int averageOfSubtree(TreeNode* root) {\n        solve(root);\n        return ans;\n    }\n};
[]