class Solution {
HashMap<Integer,Integer> map=new HashMap<>();
int max=0;
public int[] findFrequentTreeSum(TreeNode root) {
dfs(root);
List<Integer> list=new ArrayList<>();
for(int key:map.keySet()){
if(map.get(key)==max){
list.add(key);
}
}
int[] arr=new int[list.size()];
for(int i=0;i<list.size();i++){
arr[i]=list.get(i);
}
return arr;
}
private int dfs(TreeNode root){
if(root==null) return 0;
int cur=root.val+dfs(root.left)+dfs(root.right);
int count=map.getOrDefault(cur,0)+1;
map.put(cur,count);
max=Math.max(max,map.get(cur));
return cur;
}
}