Java Easy Approach | Beats 98%
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\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\n# Code\n```\n/**\n * Definition for a binary tree node.\n * public class TreeNode {\n *     int val;\n *     TreeNode left;\n *     TreeNode right;\n *     TreeNode() {}\n *     TreeNode(int val) { this.val = val; }\n *     TreeNode(int val, TreeNode left, TreeNode right) {\n *         this.val = val;\n *         this.left = left;\n *         this.right = right;\n *     }\n * }\n */\npublic class Pair{\n    int f,s;\n    Pair(int f, int s){\n        this.f = f;\n        this.s = s;\n    }\n}\n\nclass Solution {\n\n    int count;\n    public int averageOfSubtree(TreeNode root) {\n        count = 0;\n        isAverageBT(root);\n        return count;\n    }\n\n    public Pair isAverageBT(TreeNode root){\n        if(root==null){\n            return new Pair(0,0);\n        }\n        Pair left = isAverageBT(root.left);\n        Pair right = isAverageBT(root.right);\n        int sum = root.val + left.f + right.f;\n        int number = 1 + left.s + right.s;\n        if(sum/number == root.val){\n            count++;\n        } \n        return new Pair(sum,number);\n    }\n\n}\n```\n\nPlease Upvote the solution.
['Math', 'Tree', 'Depth-First Search', 'Binary Tree', 'Java']