• Courses
  • Tutorials
  • DSA
  • Data Science
  • Web Tech
July 17, 2024 |9.4K Views

Find sum of all left leaves in a given Binary Tree

  Share   Like
Description
Discussion

The idea is to traverse the tree, starting from root. For every node, check if its left subtree is a leaf. If it is, then add it to the result. 


Following is Another Method to solve the above problem. This solution passes in a sum variable as an accumulator. When a left leaf is encountered, the leaf’s data is added to sum. Time complexity of this method is also O(n). Thanks to Xin Tong (geeksforgeeks userid trent.tong) for suggesting this method.

Find sum of all left leaves in a given Binary Tree: https://www.geeksforgeeks.org/find-sum-left-leaves-given-binary-tree/