easy and user friendly approach 100% beat
Intuition\n Describe your first thoughts on how to solve this problem. \n\nstep-1 we need to find root.left total sum and root right total sum and root left hei
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\nstep-1 we need to find root.left total sum and root right total sum and root left height and root right height then simply check if satisfied the given conditon means increment count value other go to the next recursive call\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nstep-1 create a pair function one part will solve sum for left and right and other part solve the height of left and right \nstep-2 recursive call for left part and right part \nstep-3 calculate total sum for left using lh value\nstep-4 calculate total sum for right using rh value\nstep-5 compare thses values and if the condition will satisfied means increment count value \nstep-6 final step return count\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# 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    pair<int,int>f(TreeNode* root,int &cnt){\n        if(root == NULL){\n            return {0,0};\n        }\n        auto lh = f(root->left,cnt);\n        auto rh = f(root->right,cnt);\n        int sum = lh.first+rh.first+root->val;\n        int ele = lh.second+rh.second+1;\n        if(sum/ele == root->val){\n            cnt++;\n        }\n        return {sum,ele};\n    }\n    int averageOfSubtree(TreeNode* root) {\n        int cnt = 0;\n        f(root,cnt);\n        return cnt;\n    }\n};\n```
['C++']