[Algorithm] Sum of Right Leaves (Tree/C++)

Changjin
Jan 11, 2021

--

Problem Link: https://binarysearch.com/problems/Sum-of-Right-Leaves

Hello! Today we’ll be looking at a tree problem. This problem is to find the sum of all right leaf nodes’ values and can be done with a simple recursion. The key point is that during traversal, we need to track “In which direction each node comes from its parent”. Let’s take a look at the code.

Time Complexity: O(n)
- We traverse each node once so it’s linear.

[Contact]
Email: changjin9792@gmail.com
Github: https://github.com/JasonLee-cp
️✅ Medium: https://changjin9792.medium.com/

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Changjin
Changjin

No responses yet

Write a response