Solved! Leetcode 404. Sum of Left Leaves

Description Sum of Left Leaves

Given the root of a binary tree, return the sum of all left leaves.

leaf is a node with no children. A left leaf is a leaf that is the left child of another node.

Example 1

Example 2

Constraints

  • The number of nodes in the tree is in the range [1, 1000].
  • -1000 <= Node.val <= 1000

Solution

Time Complexity

O(n): where is the number of nodes in a binary tree

Space Complexity

O(1)

Rate this post

Leave a Reply