Brute force approach, java
\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 *     Tre
\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    int sum=0;\n    int count =0;\n    int level=0;\n    public int averageOfSubtree(TreeNode root) {\n        average(root);\n        return level;\n    }\n    public void preorder(TreeNode root)\n    {\n        if(root==null)\n        return ;\n\n        sum += root.val;\n        count++;\n\n\n        preorder(root.left);\n        preorder(root.right);\n    }\n    public void average(TreeNode root)\n    {\n         if(root==null)\n         return;\n\n         preorder(root);\n         if(sum/count==root.val)\n         level++;\n\n         sum=0;\n        count=0;\n\n         average(root.left);\n         average(root.right);\n    }\n}\n```
['Tree', 'Depth-First Search', 'Java']