Create A2265.java

This commit is contained in:
Mrhongxing committed 2026-10-21 00:10:50 +08:00
1 parent 09312816eb
commit 32e6c500e5
1 file changed
+25
+25
View File
@@ -0,0 +1,25 @@
package com.hong.www;
import java.util.*;
public class A2265 {
public int[] bfs(TreeNode root,ArrayList<Integer> temp){
int[] a=new int[]{0,0};
int[] b=new int[]{0,0};
if(root.left!=null){
a=bfs(root.left,temp);
}
if(root.right!=null){
b=bfs(root.right,temp);
}
if(((a[0]+b[0]+root.val)/(a[1]+b[1]+1))==root.val){
temp.add(1);
}
return new int[]{a[0]+b[0]+root.val,a[1]+b[1]+1};
}
public int averageOfSubtree(TreeNode root) {
ArrayList<Integer> temp =new ArrayList<>();
bfs(root, temp);
return temp.size();
}
}