I have used a hash-map `ctr`

to count the sum occurrence.

I have wrote a sub function `countSubtreeSum`

to travel through a tree and return the sum of the tree.

In `countSubtreeSum`

, I will travel through the left node and the right node, calculate the sum of the tree, increment the counter `ctr`

, and return the sum.

```
def findFrequentTreeSum(self, root):
if root == None: return []
def getSum(node):
if node == None: return 0
s = node.val + getSum(node.left) + getSum(node.right)
c[s] += 1
return s
c = collections.Counter()
getSum(root)
frequent = max(c.values())
return [s for s in c.keys() if c[s] == frequent]
```

Please upvote if it makes sense.

Update: I have changed a little to make the variable name shorter.