2
public int[] findFrequentTreeSum(TreeNode root) {4
HashMap<Integer, Integer> map = new HashMap<>();5
int sum = sum(root, map);8
for (Integer key : map.keySet()) {9
max = Math.max(max, map.get(key));12
for (Integer key : map.keySet()) {13
if (max == map.get(key)) {17
int[] ans = new int[count];19
for (Integer key : map.keySet()) {20
if (max == map.get(key)) {28
public int sum(TreeNode root, HashMap<Integer, Integer> map) {29
if (root == null) return 0;30
int lh = sum(root.left, map);31
int rh = sum(root.right, map);32
map.put(lh + rh + root.val, map.getOrDefault(lh + rh + root.val, 0) + 1);33
return lh + rh + root.val;