🏆C++ || DFS (easy approach)
Code\n\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n *     int val;\n *     TreeNode *left;\n *     TreeNode *right;\n *     TreeNode() : 
# 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    int s(TreeNode* root,int &v){\n        if(root==NULL)return 0;\n        v++;\n        return root->val + s(root->right,v) + s(root->left,v);\n    }\n    int ct=0;\n    int averageOfSubtree(TreeNode* root) {\n        if(root==NULL)return 0;\n        int v=0;\n        int x = s(root,v);\n        if(root->val == (x/v))ct++;\n        averageOfSubtree(root->right);\n        averageOfSubtree(root->left);\n        return ct;\n    }\n};\n```\n![upvote (2).jpg](https://assets.leetcode.com/users/images/b31c622c-b9dc-4241-abd2-48060e7f92a1_1687541613.9294002.jpeg)\n
['Tree', 'Depth-First Search', 'Binary Tree', 'C++']