Tap here to switch tabs
Problem
Ask
Submissions

Problem: Path Sum

med
30 min
Explore how to determine whether a binary tree contains a root to leaf path where the sum of node values matches a given target. This lesson guides you through using depth-first search to solve path sum problems efficiently.

Statement

Given the root of a binary tree and an integer targetSum, determine whether there exists a root to leaf path in the tree such that the sum of all node values along the path equals targetSum. Return TRUE if such a path exists, and FALSE otherwise.

Note: A leaf is defined as a node that has no left or right children.

Constraints:

  • The number of nodes in the tree is in the range [0,5000][0, 5000].

  • 1000-1000 \leq Node.val 1000\leq 1000

  • 1000-1000 \leq targetSum 1000\leq 1000

Tap here to switch tabs
Problem
Ask
Submissions

Problem: Path Sum

med
30 min
Explore how to determine whether a binary tree contains a root to leaf path where the sum of node values matches a given target. This lesson guides you through using depth-first search to solve path sum problems efficiently.

Statement

Given the root of a binary tree and an integer targetSum, determine whether there exists a root to leaf path in the tree such that the sum of all node values along the path equals targetSum. Return TRUE if such a path exists, and FALSE otherwise.

Note: A leaf is defined as a node that has no left or right children.

Constraints:

  • The number of nodes in the tree is in the range [0,5000][0, 5000].

  • 1000-1000 \leq Node.val 1000\leq 1000

  • 1000-1000 \leq targetSum 1000\leq 1000