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/