106. Path Sum
Hard
Given a binary tree and a target, return true if there exists a path from the root to a leaf whose sum of values equals the target. A node that is not a leaf cannot end the path.
Example 1
Input: raiz = [5, 4, 8, 11, null, 13, 4, 2, null, null, 1], alvo = 22
Output: true
Example 2
Input: raiz = [1, 2, 3], alvo = 4
Output: false
Constraints
- 0 <= number of nodes <= 10^4
- -10^4 <= node values, target <= 10^4
TreesDFSRecursion
Saved in this browser
Caso 1
raiz =
[5,4,8,11,null,13,4,2,null,null,1]
alvo =
22
Expected =
true
Caso 2
raiz =
[1,2,3]
alvo =
4
Expected =
true
Run checks these 2 cases. Submit runs all 7, including hidden ones.