root of a binary tree. A leaf is a node with no children, and a left leaf is a leaf that is the left child of some node.
Return the sum of the values of all left leaves, or 0 if there are none.root=tree_node([6, 2, 8, None, 4, 7, 1]) → 7
The leaves are 4, 7 and 1. Only 7 is a left child (of 8); 4 is the right child of 2 and 1 is the right child of 8. The answer is 7.
root=tree_node([-3, -5, 2, None, None, 9]) → 4
The left leaves are -5 (left of the root) and 9 (left of 2), summing to 4.
root=tree_node([10]) → 0
The root is a leaf, but it is nobody's child, so it does not count. The answer is 0.
Node.val ≤ 1000root=tree_node([6, 2, 8, None, 4, 7, 1])
7
Run checks the first 3 tests in your browser. Submit checks all 97 tests on the server, hidden ones included.