dsa · easy
Path Sum
GreyOrangeTreeRecursionFoundation
Return whether the tree has a root-to-leaf path summing to target.
Arguments
root— the binary tree; each node is[val, left, right]orNonetarget— the value you are searching for or summing to
**Example**
`` Input: [1,[2,None,None],[3,None,None]] 4 Output: True ``
Constraints
Number of nodes in [0, 500] Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.
Examples
Example 1
Input: [1,[2,None,None],[3,None,None]] 4 Expected: true
Example 2
Input: [1,[2,None,None],[3,None,None]] 5 Expected: false