Simple Recursion
/\n * Definition for a binary tree node.\n * struct TreeNode {\n *     int val;\n *     TreeNode left;\n *     TreeNode right;\n *     TreeNode() : val(0), left
/**\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 count=0;\n    int countnodes(TreeNode* root)\n    {\n        if(!root)\n            return 0;\n        else{\n             return countnodes(root->left)+countnodes(root->right)+1;\n        }\n    }\n    int findSum(TreeNode* root)\n    {\n        if(!root)\n            return 0;\n        return findSum(root->left)+findSum(root->right)+root->val;\n    }\n    int averageOfSubtree(TreeNode* root) {\n        if(!root)   \n            return 0;\n        if((findSum(root)/countnodes(root))==root->val)\n             count++;\n         averageOfSubtree(root->left);\n         averageOfSubtree(root->right);\n           \n        return count;\n            \n             \n        }\n    \n};
['Recursion', 'C']