113. Path Sum II
Practice Path Sum II 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.
Return every path that starts at the root, ends at a leaf, and whose node values add up to targetSum. Write each path as the list of its values from root to leaf. Return [] if there is none. The paths can be in any order; values can be negative.
Trees are written in level order, with null for a missing child.
Example
root = [5,4,8,11,null,13,4,7,2,null,null,5,1], targetSum = 22 -> [[5,4,11,2],[5,8,4,5]]
Constraints
- 0 <= number of nodes <= 5000
- -1000 <= Node.val <= 1000
- -1000 <= targetSum <= 1000