Solution: Path Sum
Explore how to use depth first search (DFS) to check if there exists a root to leaf path in a binary tree where the sum of node values equals a target sum. Understand the recursive approach to subtract node values from the target and identify valid paths. By the end of this lesson, you will be able to implement a solution that evaluates all root to leaf paths and returns true if any satisfy the sum condition, mastering binary tree traversal techniques for interview coding problems.
We'll cover the following...
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
. ...