K23
Path Sum to Leaf
Problem Statement & Objective
Given the root of a binary tree and an integer targetSum, return True if the tree has a root-to-leaf path such that adding up all values equals targetSum.
Function Signature (Python)
has_path_sum(root: list, target: int) -> boolInput & Output Contract
Output Rule:True veya False.
System Constraints
0 <= agac.length <= 5000
-1000 <= agac[i], hedef <= 1000Example Execution Walkthrough
agac = [5, 4, 8, 11, None, 13, 4, 7, 2], hedef = 22
5 -> 4 -> 11 -> 2 toplamı 22 -> TrueExample Test Scenarios (3)
Example 1: Yol Var
Input:
[[5,4,8,11,null,13,4,7,2],22]Expected Output:
trueExample 2: 1+2=3, 1+3=4 (5 yok)
Input:
[[1,2,3],5]Expected Output:
falseExample 3: Boş Ağaç
Input:
[[],0]Expected Output:
false