Example: Two paths
Input
root = [5,4,8,11,None,13,4,7,2,None,None,5,1], targetSum = 22
Output
[[5, 4, 11, 2], [5, 8, 4, 5]]
There are two root-to-leaf paths that sum to 22: 5->4->11->2 and 5->8->4->5.
Full lesson preview
Find all root-to-leaf paths in a binary tree where the sum of node values equals a target.
Problem statement
Task
Examples
Input
root = [5,4,8,11,None,13,4,7,2,None,None,5,1], targetSum = 22
Output
[[5, 4, 11, 2], [5, 8, 4, 5]]
There are two root-to-leaf paths that sum to 22: 5->4->11->2 and 5->8->4->5.
Input format
Output format
Constraints
Samples
Input
root = [1,2,3], targetSum = 5
Output
[]
No root-to-leaf path sums to 5.