bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 404. Sum of Left Leaves

404. Sum of Left Leaves

Leetcode Solutions

Approach: Iterative Tree Traversal (Pre-order)

  1. Initialize an empty stack and push the root node onto it.
  2. Initialize a variable total to 0 to keep track of the sum of left leaves.
  3. While the stack is not empty: a. Pop the top node from the stack. b. If the left child of the node is a leaf, add its value to total. c. Push the right child of the node onto the stack (if it exists). d. Push the left child of the node onto the stack (if it exists).
  4. Return the value of total.
UML Thumbnail

Approach: Recursive Tree Traversal (Pre-order)

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...