Description
Given the root of a binary tree, return the sum of all left leaves. A left leaf is a leaf that is the left child of its parent.
Examples
Input:
root = [3,9,20,null,null,15,7]Output:
24Explanation:
Left leaves: 9 + 15 = 24.
Input:
root = [1]Output:
0Explanation:
A single-node tree has no left leaves, so the sum is 0.
Input:
root = [5,2,8,1,3,null,9,null,null,null,6]Output:
7Explanation:
Left leaves are nodes that are leaves (no children) and are the left child of their parent. In this tree, node 1 (left child of 2) and node 6 (left child of 3) are left leaves. Sum: 1 + 6 = 7.
Constraints
- •
1 ≤ nodes ≤ 1000