EASIEST JAVA SOLUTION EVER !!! ( Brute Force Approach and Better Pair Approach)  2 Approaches !!!
Intuition\n- The Brute Approach is very Intuitive.\n- For every node we get the sum of it\'s left substree + sum of it\'s right subtree + value of itself divide
# Intuition\n- **The Brute Approach is very Intuitive.**\n- **For every node we get the sum of it\'s left substree + sum of it\'s right subtree + value of itself divided by total numbe rof nodes.**\n\n# Approach\n**Brute Force Approach**\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 */\nclass Solution {\n\n    public static int numOfNodes(TreeNode node){\n\n        if(node == null){\n            return 0;\n        }\n\n        return numOfNodes(node.left) + numOfNodes(node.right) + 1;\n\n    }\n\n    public static int getSum(TreeNode node){\n\n        if(node == null){\n            return 0;\n        }\n\n        return getSum(node.left) + getSum(node.right) + node.val;\n\n    }\n\n    public static void helper(TreeNode node){\n\n        if(node == null){\n            return;\n        }\n\n        int sum = getSum(node.left) + getSum(node.right) + node.val;\n        int n = numOfNodes(node.left) + numOfNodes(node.right) + 1;\n\n        if(n!=0 && (node.val == (sum/n))){\n            ans++;\n        }\n\n        helper(node.left);\n        helper(node.right);\n\n    }\n\n    public static int ans;\n\n    public int averageOfSubtree(TreeNode root) {\n\n        ans = 0;\n        \n        helper(root);\n\n        return ans;\n\n    }\n\n}\n```\n\n\n# Intuition\n- **Creating a new class Pair.**\n- **This will allow us to get the sum of the substree as well as the number of nodes simultaneously.**\n\n# Approach\n**Better Pair Approach**\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 */\n\nclass Pair{\n\n    int sum;\n\n    int nodes;\n\n    Pair(int sum, int nodes){\n        this.sum = sum;\n        this.nodes = nodes;\n    }\n\n}\n\nclass Solution {\n\n    public static Pair helper(TreeNode node){\n\n        if(node == null){\n            return new Pair(0, 0);\n        }\n\n        Pair left = helper(node.left);\n\n        Pair right = helper(node.right);\n\n        int totalSum = left.sum + right.sum + node.val;\n\n        int num = left.nodes + right.nodes + 1;\n\n        if(num != 0 && (totalSum/num) == node.val){\n            ans++;\n        }\n\n        return new Pair(totalSum, num);\n\n    }\n\n    public static int ans;\n\n    public int averageOfSubtree(TreeNode root) {\n        \n        ans = 0;\n\n        helper(root);\n\n        return ans;\n\n    }\n\n}\n```
['Java']