Given a binary tree, compute the sum of all left leaf nodes.
You are given the root of a binary tree. A leaf is a node with no children. A left leaf is a leaf node that is the left child of its parent.
Return the sum of all left leaves in the tree.
0.This is a tree traversal problem where you need to keep track of whether the current node was reached as a left child.
Example 1
Input
root = [3,9,20,null,null,15,7]
Output
24
Explanation
The left leaves are 9 and 15. Their sum is 24.
Example 2
Input
root = [1]
Output
0
Explanation
The root is not a left leaf, and there are no other nodes.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.