437. Path Sum III
Practice Path Sum III for free on NudgeCode: Medium, Binary Tree pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.
Count the downward paths whose node values add up to targetSum. A path has at least one node; it can start and end at any node, but it must only go from parent to child, never back up. Values can be negative.
Trees are written in level order, with null for a missing child.
Example
root = [10,5,-3,3,2,null,11,3,-2,null,1], targetSum = 8 -> 3
The three paths are 5 -> 3, 5 -> 2 -> 1 and -3 -> 11.
Constraints
- 0 <= number of nodes <= 1000
- -10^9 <= Node.val <= 10^9
- -1000 <= targetSum <= 1000