Path Sum
Path Sum You are given the root of a binary tree and an integer targetSum . Your task is to determine whether the tree has any root-to-leaf path such that adding up all the values along the path equals targetSum . A leaf is a node with no children. Example Input : root = [ 5 , 4 , 8 , 11 , null , 13 , 4 , 7 , 2 , null , null , null , 1 ] targetSum = 22 Output : true This is because the path 5 → 4 → 11 → 2 adds up to 22. Best Data Structure for the Job Binary trees are already built using the classic TreeNode class. We just need: A recursive function to traverse the tree, tracking the remaining target sum. Different Approaches Approach 1: Recursive (Depth-First Search) We use recursion to walk through every path from root to leaf. At each node, we subtract the node’s value from the remaining targetSum , and pass it down the recursive call. When we reach a leaf, we check if the remaining sum equals the leaf’s value. /** * Definition for a binary tree node. * pub...