Determine whether a binary tree contains a root-to-leaf path whose node values add up to a target sum.
Given the root of a binary tree and an integer targetSum, determine whether the tree has at least one root-to-leaf path such that the sum of the node values along that path equals targetSum.
A path must start at the root and end at a leaf. A leaf is a node with no children.
roottargetSumtrue if there exists at least one root-to-leaf path whose values sum to targetSum.false.targetSum are integers.Example 1
Input
root = [5,4,8,11,null,13,4,7,2,null,null,null,1], targetSum = 22
Output
true
Explanation
One valid path is 5 → 4 → 11 → 2, and its sum is 22.
Example 2
Input
root = [1,2,3], targetSum = 5
Output
false
Explanation
The root-to-leaf paths are 1 → 2 and 1 → 3, with sums 3 and 4.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.