Example 3 : Sum of Left Leaves

TopicDifficultyCompanies
Binary Tree
EASY
Facebook

Write a program to find the sum of all left leaves in a given binary tree.

Problem Note

  • A leaf node is a node having no child node.

Example

Input: Given binary tree, [5, 3, 6, 8, -1, 9, -1]
5
/ \
3 6
/ /
8 9
Output: 17
Explanation: There are two left leaves in the binary tree, with values 8 and 9 respectively. Hence, the sum is 17.

Code Editor

Practice and Learn

Best way to learn is through solving real problems. Practice this problem in this code editor.