simplest DFS Solution 100% beats🔥
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# 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 Pair{\n    int getKey;\n    int getValue;\n    public Pair(int a,int b){\n        this.getKey=a;\n        this.getValue=b;\n    }\n}\nclass Solution {\n    int count;\n    public int averageOfSubtree(TreeNode root) {\n        solve(root);\n        return count;\n    }\n    public Pair solve(TreeNode root){\n        if(root==null) {\n            Pair p = new Pair(0,0);\n            return p;\n        }\n        Pair left1 = solve(root.left);\n        Pair right1 = solve(root.right);\n        int n= left1.getValue+right1.getValue+1;\n        int sum=root.val+left1.getKey+right1.getKey;\n        int avg = sum/n;\n        if(avg==root.val) count++;\n        return new Pair(sum,n);\n    }\n}\n```
['Depth-First Search', 'Java']