Left Leaves

BINARY TREE
DEPTH-FIRST SEARCH
BREADTH-FIRST SEARCH

Problem

Given the root of a binary tree, return the sum of all left leaves. A leaf is a node with no children. A left leaf is a leaf that is the left child of another node.

Examples

sumOfLeftLeaves([1,2,3,4,5]) // returns 4 // Only the node with value 4 is a left leaf. sumOfLeftLeaves([5,4,null,3,null,2]) // returns 2 // The node with value 2 stands as the sole left leaf.
Loading...
1
2
4
5
3