Back to problems Sign in to unlock
Leetcode
Medium
Trees
Recursion
Sum Of Left Leaves
Given a binary tree, compute the sum of all left leaf nodes.
Acceptance 0%
Problem Statement
Problem
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.
Notes
- The root itself is not considered a left leaf.
- If the tree has no left leaves, return
0.
Intuition
This is a tree traversal problem where you need to keep track of whether the current node was reached as a left child.
Input Format
- A binary tree root node is provided.
- The tree is represented in standard level-order form when serialized for testing.
Output Format
- Return a single integer: the sum of all left leaf node values.
Constraints
- The number of nodes is non-negative and fits within typical interview constraints.
- Node values may be negative or positive integers.
- The answer fits in a 32-bit signed integer.
Examples
Sample cases returned by the problem API.
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
Unlock deeper context for this problem
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.
Guided hints
Editorial and discussion links
Concept map and variants
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.