# Leetcode 437 - Path Sum III

`Note:`

- Path sum on a tree, usually we need DFS.
- What should we return in each
`DFS`

? - It should include
`node.val`

, and add`node.val`

to`every combination from children`

. - Base case: Return [].
- What to do in each recursion?
- If
`node.val === target`

, ans++; - Put
`left`

and`right`

results together, and see how many`target - val`

are in there.

- If
- Return
`[val, ...left.map(e => e + val), ...right.map(e => e + val)]`

; - Basically,
`preSum`

of children nodes.

`Question:`

Given the `root`

of a binary tree and an integer `targetSum`

, return the number of paths where the sum of the valuesÂ along the path equalsÂ `targetSum`

.

The path does not need to start or end at the root or a leaf, but it must go downwards (i.e., traveling only from parent nodes to child nodes).

`Example:`

1 | Input: root = [10,5,-3,3,2,null,11,3,-2,null,1], targetSum = 8 |

`Code:`

1 | /** |