From 32e6c500e50103c42e1e1e75b42eb539f862c369 Mon Sep 17 00:00:00 2001 From: Mrhongxing <154480715+Mrhongxing@users.noreply.github.com> Date: Wed, 21 Oct 2026 00:10:50 +0800 Subject: [PATCH] Create A2265.java --- src/com/hong/www/A2265.java | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/com/hong/www/A2265.java diff --git a/src/com/hong/www/A2265.java b/src/com/hong/www/A2265.java new file mode 100644 index 0000000..db1ac0a --- /dev/null +++ b/src/com/hong/www/A2265.java @@ -0,0 +1,25 @@ +package com.hong.www; + +import java.util.*; + +public class A2265 { + public int[] bfs(TreeNode root,ArrayList 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 temp =new ArrayList<>(); + bfs(root, temp); + return temp.size(); + } +} \ No newline at end of file