Practice/Meta/Leetcode 112. Path Sum
CodingMust
Given a binary tree and an integer target sum, determine if there exists a path from the root to any leaf node where the sum of all node values along that path equals the target sum.
A leaf node is defined as a node that has no children (both left and right pointers are null).
Example 1:
Input: root = [5,4,8,11,null,13,4,7,2,null,null,null,1], targetSum = 22 Output: true Explanation: The path 5→4→11→2 has a sum of 5+4+11+2 = 22
Example 2:
Input: root = [1,2,3], targetSum = 5 Output: false Explanation: The two paths are 1→2 (sum=3) and 1→3 (sum=4), neither equals 5
Example 3:
Input: root = [], targetSum = 0 Output: false Explanation: An empty tree contains no paths
Example 4:
Input: root = [1,2], targetSum = 1 Output: false Explanation: Even though the root equals 1, it's not a leaf node. The only path is 1→2 (sum=3)