C++ Solution | Simple Recursion
\n\nclass Solution {\npublic:    \n    int count(TreeNode* root)\n    {\n        //if tree is empty\n        if(root==NULL) return 0;\n        \n        //if tr
\n```\nclass Solution {\npublic:    \n    int count(TreeNode* root)\n    {\n        //if tree is empty\n        if(root==NULL) return 0;\n        \n        //if tree has single node/leaf node\n        if(root->left==NULL && root->right==NULL) return 1;    \n        \n        return 1 + count(root->left) + count(root->right);\n    }\n    \n    \n    int sum(TreeNode* root)\n    {\n        //if tree is empty\n        if(root==NULL) return 0;\n        \n        return root->val + sum(root->left) +  sum(root->right);\n    }\n    \n    int averageOfSubtree(TreeNode* root) {\n        \n        //if tree is empty\n        if(root==NULL) return 0;\n        \n        //if tree has single node/leaf node\n        if(root->left==NULL && root->right==NULL) return 1;\n        \n        //return value or Boolean condition(1 or 0) + rec(root->left) + rec(root->right)\n        return (sum(root)/count(root)==root->val) + averageOfSubtree(root->left) + averageOfSubtree(root->right);\n\n    }\n};\n```\n
['Recursion', 'C']