The problem. 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.
Input: root = [3, 9, 20, null, null, 15, 7] Output: 24
Input: root = [1] Output: 0 (the root isn't anyone's left child)Two conditions must both hold: the node is a leaf (no children) and it is a left child. A node can check the first by itself, but not the second — only its parent knows which side it hangs on.
Free account
Sign up to read the rest of this lesson: 6 more sections, 2 drawings, a dry-run simulator and code in JavaScript, Python, Java and C++.
Still to come