🔥POTD 🔥 02/11/23 🔥C++ ✅✅ Binary Tree 💯💯 ⬆⬆⬆
\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(
\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, pair<int, int>> solve(TreeNode* root)    {\n        if(!root)   return {0, {0, 0}};\n        pair<int, pair<int, int>> lAns = solve(root->left), rAns = solve(root->right);\n        int totalSum = lAns.second.first + rAns.second.first + root->val;\n        int totalNode = lAns.second.second + rAns.second.second + 1;\n        int ans = lAns.first + rAns.first;\n        if(totalSum / totalNode == root->val)  ans++;\n        return {ans, {totalSum , totalNode}};\n    }\n\n    int averageOfSubtree(TreeNode* root) {\n        return solve(root).first;\n    }\n};\n```
['Tree', 'Depth-First Search', 'Recursion', 'Binary Tree', 'C++']