Java | DFS
\nclass Solution {\n    int res = 0;\n    public int averageOfSubtree(TreeNode root) {\n        dfs(root);\n        return res;\n    }\n    \n    private int[] 
```\nclass Solution {\n    int res = 0;\n    public int averageOfSubtree(TreeNode root) {\n        dfs(root);\n        return res;\n    }\n    \n    private int[] dfs(TreeNode node) {\n        if(node == null) {\n            return new int[] {0,0};\n        }\n        \n        int[] left = dfs(node.left);\n        int[] right = dfs(node.right);\n        \n        int currSum = left[0] + right[0] + node.val;\n        int currCount = left[1] + right[1] + 1;\n        \n        if(currSum / currCount == node.val) {\n            res++;\n        }\n            \n        return new int[] {currSum, currCount};\n    }\n}\n```
['Depth-First Search', 'Java']