Data Structures19 sections · 729 units
Open in Course

Problem - Path Sum

Root-to-leaf with target

Given the root of a binary tree and an integer targetSum, return true if the tree has a root-to-leaf path such that adding up all values along the path equals targetSum.

A leaf is a node with no children. Example: For tree [5,4,8,11,null,13,4,7,2,null,null,null,1][5,4,8,11,null,13,4,7,2,null,null,null,1] and target 22, the path 541125 \to 4 \to 11 \to 2 sums to 22. Constraints: up to 50005000 nodes, values from 1000-1000 to 10001000, target from 1000-1000 to 10001000.