less than 1 minute read

Given a binary tree root, return the sum of all leaves that are right children.

Constraints

  • n ≤ 100,000 where n is the number of nodes in root

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

Examples

Example 1

Input

  • root =

Output

  • answer = 2

Example 2

Input

  • root =

Output

  • answer = 10

Explanation

Since 7 + 3 = 10.

Solution

Leave a comment