For every node in the tree, treat it as a starting point, and count how many downward paths from that node sum to the target.
So the problem is divided into two parts:
A function that counts valid paths starting from the current node
Recursively apply this logic to every node in the tree
For every node, I recursively count the number of downward paths starting from that node that sum to the target. Since each node may re-traverse its subtree, the worst case time complexity is O(n2).
Method 2: Prefix
Use HashMap to store the prefix, and if there exist currSum - target, which means we find the values sum equals to target.