Search⌘ K
AI Features

Path Sum

Explore how to apply depth-first search on binary trees to check if any root-to-leaf path equals a given target sum. Understand the problem constraints and practice implementing a solution that returns true when such a path exists and false otherwise.

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 ...