Path Sum II
Given the root of a binary tree and an integer targetSum, return all root-to-leaf paths whose node values sum to targetSum. Each path is returned as the list of node values from root to leaf, and the order of the paths does not matter.
Open official problem prompt ↗Produce the list of every complete root-to-leaf route whose values total targetSum.
Explore a cave with a rope you pay out as you go and reel back at dead ends; every time you reach an exit at exactly the right depth, you photograph the current rope layout.
- Input
- root = [5,4,8,11,null,13,4,7,2,null,null,5,1], targetSum = 22
- Output
- [[5,4,11,2],[5,8,4,5]]
- Why
- Both 5+4+11+2 and 5+8+4+5 equal 22, and both end at leaves.
The number of nodes is in the range [0, 5000]-1000 <= Node.val <= 1000-1000 <= targetSum <= 1000