Home | Projects | Notes > Problem Solving > LC - E - 404. Sum of Left Leaves (DFS)

LC - E - 404. Sum of Left Leaves (DFS)

 

Solutions in C++

Solution 1

This solution uses Depth-First Search (DFS) algorithm.

The strategy is to perform DFS and accumulate the values of the left leaves only.

Complexity Analysis:

Solution:

 

Solution 2

This solution does not use helper function or additional variable.

Complexity Analysis:

Solution: